gpt4 book ai didi

typescript - 从组件打开 ng-bootstrap 模态

转载 作者:行者123 更新时间:2023-12-05 00:40:22 26 4
gpt4 key购买 nike

我有一个 angular5 组件,它应该触发引导模型打开。它使用按钮效果很好,但没有关于如何在组件内以编程方式打开 ng-bootstrap 模态(bootstrap 4)的明确 api 文档。

sample-modal.ts

constructor(private modalService: NgbModal) {}

open(content){
this.modalService.open(content);
}

sample-modal.html

<ng-template #content let-c="close" let-d="dismiss">
<div class="modal-header">
<h4 class="modal-title">Modal title</h4>
<button type="button" class="close" aria-label="Close" (click)="d('Cross click')">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<p>One fine body&hellip;</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-outline-dark" (click)="c('Close click')">Close</button>
</div>
</ng-template>

最佳答案

Angular 9 版本

模板

<ng-template #myModal let-modal>
<h1>My Modal</h1>
</ng-template>

组件

@ViewChild('myModal') myModal : any;

openModal() {
this.modalService.open(this.myModal);
}

关于typescript - 从组件打开 ng-bootstrap 模态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50117644/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com