我有一个用 ng-template 包裹的模态,
<ng-template #template>
<div class="modal-header">
<h4 class="modal-title pull-left">Modal for user id : {{ modalService.config.initialState.id }}</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>
</ng-template>
Run Code Online (Sandbox Code Playgroud)
我有一个按钮可以打开这个模式,例如
<button type="button" class="btn btn-primary" (click)="openModal(template)">Create template modal</button>
openModal(template: TemplateRef<any>) {
const user = {
id: 10
};
this.modalRef = this.modalService.show(template, {
initialState : user
});
}
Run Code Online (Sandbox Code Playgroud)
当我将模板作为参数传递时,这将起作用。
如何在不传递参数的情况下打开此模式?就这样吧,我没有按钮,我想在 ngOninit 上打开模式。怎么可能呢?