【发布时间】:2017-01-20 17:16:07
【问题描述】:
玩弄NgbModal 并想从模板代码之外的其他地方触发打开方法-> open(content: string | TemplateRef<any>, options: NgbModalOptions) <button (click)="open(content)">Launch demo modal</button>,代码运行良好,当然所有代码都来自 html 文件中的<template></template>。
试图用这个来完成一些事情:
logoutScreenOptions: NgbModalOptions = {
backdrop: 'static',
keyboard: false
};
lockedWindow: NgbModalRef;
lockedScreenContent= `
<template #content let-c="close" let-d="dismiss">
<div class="modal-header" style="text-align: center">
<h3 class="modal-title">Title</h3>
</div>
<div class="modal-body">
<p>Body</p>
</div>
<div class="modal-footer">
<p>Footer</p>
</div>
</template>
`;
openLockedScreen(){
this.open(this.lockedScreenContent);
}
open(content) {
console.log(content);
this.lockedWindow = this.modalService.open(content, this.logoutScreenOptions);
this.lockedWindow.result.then((result) => {
this.closeResult = `Closed with: ${result}`;
}, (reason) => {
this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
});
}
代码运行没有错误,模式打开如下: Modal without rendered content ...这不是我想要的!
也这样尝试,结果一模一样:
lockedScreenContent= `
<div class="modal-header" style="text-align: center">
<h3 class="modal-title">Title</h3>
</div>
<div class="modal-body">
<p>Body</p>
</div>
<div class="modal-footer">
<p>Footer</p>
</div>
`;
我错过了什么?难道不能只传递一个字符串作为“内容”参数吗?
我也无法理解如何使用 ts 文件中的 templateRef 参数!
【问题讨论】:
标签: angular modal-dialog ng-bootstrap