[英]How to close open modal popup on button click?
我有一個AppComponent
,其中有一個登錄按鈕。 當用戶單擊登錄按鈕時, SigninComponent
將作為模式彈出SigninComponent
打開。
如何在單擊按鈕時關閉打開的模式彈出窗口?
這是我的代碼:
app.component.html
<ng-template #content let-c="close" let-d="dismiss">
<app-signin></app-signin>
</ng-template>
app.component.ts
openModalPopup(content:string){
this.modalPopup.open(content);
}
模態彈出
constructor(private modalService: NgbModal) { }
open(content: string) {
this.modalService.open(content,{ centered: true }).result.then((result) => {
this.closeResult = `Closed with: ${result}`;
}, (reason) => {
this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
});
}
getDismissReason(reason: any): string {
if (reason === ModalDismissReasons.ESC) {
return 'by pressing ESC';
} else if (reason === ModalDismissReasons.BACKDROP_CLICK) {
return 'by clicking on a backdrop';
} else {
return `with: ${reason}`;
}
}
幫我解決這個問題。
模型彈出服務返回打開的彈出參考。
// popupRef : NgbModalRef;
this.popupRef = this.modalService.open(content,{ centered: true });
然后使用返回的引用並關閉打開的彈出窗口。 喜歡 :
urClickMethod(){
this.popupRef.close();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.