2

这是我的代码:

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

任何建议这里出了什么问题?

4

2 回答 2

8

您可以将模型的引用作为承诺打开并关闭它。

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();
于 2017-09-15T12:25:12.560 回答
0

打开模态:

constructor(
    private modalService: NgbModal
) { }

this.modalService.open()

关闭激活模式:

constructor(
    public activeModal: NgbActiveModal
) { }

editDocumentRow = function (documentId, modal) {
    this.activeModal.dismiss();
})
于 2017-09-15T12:11:21.353 回答