2017-09-15 115 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

我也得到這個錯誤:'錯誤:無法激活一個已經激活的插座' –