Angular(2/4)modalService.close()无法正常工作

Adr*_*rma 1 bootstrap-modal viewchild angular

这是我的代码:

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
})
Run Code Online (Sandbox Code Playgroud)

}

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

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

有什么建议吗?

Sac*_*aka 6

您可以将模型的参考作为promise打开并关闭。

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)}`;
        });


    })
}
Run Code Online (Sandbox Code Playgroud)

现在您可以关闭模​​型

this.modalReference.close();
Run Code Online (Sandbox Code Playgroud)