所以我有NgbModal
一个表格,我想要实现的是在成功提交时关闭它。
这是我的模态组件:
@Component({
selector: 'create-update-transaction',
templateUrl: './CreateOrUpdateTransaction.html',
providers: [AccountTransactionsService]
})
export class CreateOrUpdateTransactionComponent {
closeResult: string;
modalRef: NgbModalRef;
@Input() transaction: Transaction = new Transaction();
@Output() onSubmit: EventEmitter<void> = new EventEmitter<void>();
constructor(private modalService: NgbModal,
private transactionsService: AccountTransactionsService) {}
sendTransaction(): void{
let localModalRef = this.modalRef;
this.transactionsService.createOrUpdateTransaction(this.transaction, (isSuccessful)=>{
if (isSuccessful) {
this.onSubmit.emit();
localModalRef.close(); //<--- The problem is here
}
});
}
open(content) {
this.modalRef = this.modalService.open(content).result.then((result) => {
this.closeResult = `Closed with: ${result}`;
}, (reason) => {
this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
});
}
}
localModalRef.close is not a function
尝试调用已保存的 close 方法时收到错误NgbModalRef