2017-09-15 118 views
1

这是我的代码:角(2/4)modalService.close()不工作

import { NgbModal } from '@ng-bootstrap/ng-bootstrap';

constructor(private http: Http, private route: ActivatedRoute,private router: Router, private modalService: NgbModal) { } 

editDocumentRow = function (documentId, modal) { 
    this.http.get(ConstantComponent.url + '/documentmanagerapi/Get/' + documentId).map((res: Response) => res.json()).subscribe(data => { 
    this.documentsRowDetails = data 
    this.modalService.open(modal) 
    this.modalService.close() // not working 
}) 

}

我想在不同的功能使用this.modalService.close()。但它甚至不在this.modalService.open(modal)完美运行的相同功能中工作。

我收到此错误: this.modalService.close is not a function

任何建议,有什么错在这里去了?

+1

modalService.close()将无法正常工作,而不是使用this.activeModal.dismiss() – Chandru

回答

1

就可以得到模型作为承诺开放的参考,并将其关闭。

editDocumentRow = function(documentId, modal) { 
    this.http.get(ConstantComponent.url + '/documentmanagerapi/Get/' + documentId).map((res: Response) => res.json()).subscribe(data => { 
     this.documentsRowDetails = data 
     this.modalService.open(modal) 
     this.modalReference = this.modalService.open(modal); 
     this.modalReference.result.then((result) => { 
      this.closeResult = `Closed with: ${result}`; 
     }, (reason) => { 
      this.closeResult = `Dismissed ${this.getDismissReason(reason)}`; 
     }); 


    }) 
} 

现在你可以关闭模​​型

this.modalReference.close(); 
1

打开模式:

constructor(
    private modalService: NgbModal 
) { } 

this.modalService.open() 

关闭激活模态:

constructor(
    public activeModal: NgbActiveModal 
) { } 

editDocumentRow = function (documentId, modal) { 
    this.activeModal.dismiss(); 
}) 
+0

我收到此错误:'错误:没有提供程序NgbActiveModal !' –

+0

我从'@ ng-bootstrap/ng-bootstrap'添加了这个'import {NgbModal,NgbActiveModal};'但它似乎没有帮助。请建议 –

+0

我也得到这个错误:'错误:无法激活一个已经激活的插座' –