1. 使用let-*对打开的modal弹窗进行关闭操作,用户点击"确定"按钮或者点击"x"按钮关闭
<ng-template #content let-c="close">
<div class="modal-header">
<h4 class="modal-title" id="modal-basic-title">题目</h4>
<button type="button" class="close" aria-label="Close" (click)="c('Cross click')">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body" id="video-modal-body">
<form>
<div class="form-group">
<p> there is content......</p>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-outline-dark" (click)="c('Save click')">确定</button>
</div>
</ng-template>
2. 使用NgbModalRef对ngbModalRef对象进行操作(包括open和close操作)
代码如下:
// 第一步: 声明变量
modalRef: NgbModalRef;
// 第二步: 获取实例
openModal() {
this.modalRef = this.modalService.open(content, {size: 'lg'});
this.modalRef.result.then(
result => {
// do something...
},
reason => {
this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
}
);
}
// 第三步: 关闭弹窗
closeModal() {
this.modalRef.close()
}
3. 使用NgbActiveModal关闭(待研究)