【问题标题】:Ngx-bootstrap Error as self.context.openModal.template is not a function for ModalNgx-bootstrap 错误,因为 self.context.openModal.template 不是 Modal 的功能
【发布时间】:2018-01-14 17:35:18
【问题描述】:

我在这里使用 ngx-bootstrap 作为模态,因为我正在使用来自 ngx-bootstrap 网站的他的第一个模态示例。为什么我无法 2 打开我的模板这是我的代码

<button type="button" class="btn btn-primary" (click)="openModal.template()">Create template modal</button>

<template #template>
    <div class="modal-header">
        <h4 class="modal-title pull-left">Modal</h4>
        <button type="button" class="close pull-right" aria-label="Close" (click)="modalRef.hide()">
            <span aria-hidden="true">&times;</span>
        </button>
    </div>
    <div class="modal-body">
        This is a modal.
    </div>
</template>

Module.ts

import { ModalModule } from 'ngx-bootstrap';
  imports: [AlertModule.forRoot(), ModalModule.forRoot()]

Component.ts

import { BsModalService } from 'ngx-bootstrap';
import { BsModalRef } from 'ngx-bootstrap/';
    public modalRef: BsModalRef;
 constructor( private modalService: BsModalService){}
 openModal(template: TemplateRef<any>) {
       debugger;
        this.modalRef = this.modalService.show(template);
    }

【问题讨论】:

    标签: twitter-bootstrap typescript angular2-forms ngx-bootstrap


    【解决方案1】:

    您错误地调用了openModal 方法。 这个openModal.template() 假定openModal 是一个具有template() 方法的对象或类实例。

    正确的方式是openModal(template)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-15
      • 1970-01-01
      相关资源
      最近更新 更多