我正在使用 ng-bootstrap,我想在我构建的组件库中添加一个可重用的模式。
我有我的模板
<p>
<ng-template #messageModal let-closeModal="close('Cross click')">
<div id="resultModal">
<div class="modal-header">
<h4 class="mt-3">{{header}}
</h4>
<button id="messageModalClose" type="button" class="close" aria-label="Close" (click)="closeModal">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
{{message}}
</div>
</div>
</ng-template>
</p>
和组件
import { Component, OnInit, ViewEncapsulation, Input } from '@angular/core';
import { NgbModal, NgbModalOptions } from '@ng-bootstrap/ng-bootstrap';
@Component({
selector: 'ms-modal',
templateUrl: './ms-modal.component.html',
styleUrls: ['./ms-modal.component.scss'],
encapsulation: ViewEncapsulation.None,
})
export class MsModalComponent implements OnInit {
@Input() header: string;
@Input() message:string;
private _modalOptions: NgbModalOptions = {
backdrop: 'static',
keyboard: false,
size: 'lg',
centered: true
};
constructor(private modalService: NgbModal) { }
ngOnInit() {
}
OpenModal(_messageModal) {
this.modalService.open(_messageModal, this._modalOptions);
}
}
我为标题和消息添加了@Inputs 我的组件库构建良好
在我将组件库导入的应用程序中,我添加了模态标记
<ms-modal *ngIf="showModal==true" [header]="header" [message]="message">
</ms-modal>
当我设置 showModal=true 什么都没有发生。
showModal:any = false;
this.showModal = "true";
我想我不确定如何正确连接它以在我的各种应用程序中使用我的组件库中的模态。