这里我使用 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">×</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);
}