gpt4 book ai didi

angular - 如何以编程方式关闭 ng-bootstrap 模式?

转载 作者:太空狗 更新时间:2023-10-29 16:50:21 26 4
gpt4 key购买 nike

我有一个模式:

<template #warningModal let-c="close" let-d="dismiss">
<div class="modal-header">
<button type="button" class="close" aria-label="Close" (click)="d('Cross click')">
<span aria-hidden="true">&times;</span>
</button>
<h4 class="modal-title">Warning</h4>
</div>
<div class="modal-body">
The numbers you have entered result in negative expenses. We will treat this as $0.00. Do you want to continue?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" (click)="c('Close click')">No</button>
<button type="button" class="btn btn-secondary" (click)="submit()">Yes</button>
</div>
</template>

每当我单击"is"时,我希望它调用一个函数并自行关闭。
在我的 Controller 中,我有 @ViewChild('warningModal') 警告;submit() 中,我有 this.warning.close();,但每当我单击"is"时,我都会得到 this.warning.close is not a function

如何让它按照我想要的方式工作?

最佳答案

为了阐述 pkozlowski.opensource 的回应,我实际获得对 NgbModalRef 类的引用的方式是修改他在 this.modalService.open 上的 plunker 中的内容,如下所示:

this.modalReference = this.modalService.open(content);
this.modalReference.result.then((result) => {
this.closeResult = `Closed with: ${result}`;
}, (reason) => {
this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
});

然后我可以调用:

this.modalReference.close();

这就像一个魅力。哦,别忘了把 define modalReference 放在类的顶部:

modalReference: any;

关于angular - 如何以编程方式关闭 ng-bootstrap 模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40382319/

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