通过 TemplateRef 手动触发 ngx-bootstrap 模态

Manually trigger ngx-bootstrap modal via TemplateRef

我想通过打字稿动态触发模态。我知道这应该很容易,所以我可能正在查看一些东西。

模板中的某处:

<ng-template #adminmodal>.....Some content right here......</ng-template>

分量:

正在尝试从 #adminmodal

创建一个 TemplateRef

@ViewChild('adminmodal', { read: TemplateRef }) _adminModalRef: TemplateRef<any>;

尝试触发惨遭失败

this.modalRef = this.modalService.show(this._adminModalRef);

它打开了一个模态,但是模态内容是空的,所以我的方法有问题。

您的方法应该可行,也许 ngx-boostrap 中存在错误 (https://github.com/valor-software/ngx-bootstrap/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+modal)

根据您可以尝试的文档,另一种方法是通过 modalDirective

模板

<div class="modal fade" bsModal #modal="bs-modal">...</div>

打字稿

  @ViewChild(ModalDirective) modal: ModalDirective;

  showModal() {
    this.modal.show();
  }

希望这对你有所帮助,祝你好运!