首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法关闭ng-bootstrap模式

无法关闭ng-bootstrap模式
EN

Stack Overflow用户
提问于 2016-09-11 20:12:28
回答 1查看 7K关注 0票数 5

所以我有一个包含表单的NgbModal,我想要实现的是在成功提交时关闭它。

这是我的ModalComponent:

代码语言:javascript
复制
@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)}`;
        });
    }
}

尝试调用保存的NgbModalRef的close方法时收到localModalRef.close is not a function错误

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-09-11 20:39:26

这对你来说应该是可行的:

代码语言:javascript
复制
open(content) {
  this.modalRef = this.modalService.open(content);
  this.modalRef.result.then((result) => {
    this.closeResult = `Closed with: ${result}`;
  }, (reason) => {
      this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
  });
}

否则,您的modalRef变量将引用ZoneAwarePromise对象

票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39435950

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档