Angular(2/4) modalService.close() 不工作

Angular(2/4) modalService.close() is not working

这是我的代码:

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

这里出了什么问题有什么建议吗?

打开模式:

constructor(
    private modalService: NgbModal
) { }

this.modalService.open()

关闭激活模式:

constructor(
    public activeModal: NgbActiveModal
) { }

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

你可以获取模型的引用作为承诺打开并关闭它。

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();