这是我的代码:
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
任何建议,这里出了什么问题?
您可以打开模型的参考作为诺言并关闭它。
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();
打开模式:
constructor(
private modalService: NgbModal
) { }
this.modalService.open()
关闭激活模式:
constructor(
public activeModal: NgbActiveModal
) { }
editDocumentRow = function (documentId, modal) {
this.activeModal.dismiss();
})