0

这里我使用 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>

模块.ts

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

组件.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);
    }
4

1 回答 1

1

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

正确的方法是openModal(template)

于 2017-08-08T09:36:36.427 回答