这是我的代码:
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
有什么建议在这里出了什么问题?
答案 0 :(得分:5)
您可以将模型的引用作为承诺打开并关闭它。
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 :(得分:-1)
打开模态:
constructor(
private modalService: NgbModal
) { }
this.modalService.open()
关闭激活模态:
constructor(
public activeModal: NgbActiveModal
) { }
editDocumentRow = function (documentId, modal) {
this.activeModal.dismiss();
})