angular - 如何从应用程序中的任何位置打开模式
问题描述
我需要将所有模式放在一个地方,以便我可以从应用程序中的任何位置访问任何模式。这可能吗。
现在,我正在以下面的方式打开一个模式。
openModal(template: TemplateRef<any>,cssClass:any) {
if(this.modalRef) {
this.closeModal();
}
this.config.class = cssClass;
this.modalRef = this.modalService.show(template, this.config);
}
closeModal() {
if(this.modalRef) {
this.modalRef.hide();
this.modalRef = null;
}
}
在我的 HTML 中
<button (click)="openModal(someModal,'some-class')">Click</button>
<ng-template #someModal> <div class="modal-body"> Login Here </div></ng-template>
解决方案
您可以创建一个自定义指令,您可以在其中从应用程序的任何位置访问模式。只有模态的内容会根据需求的上下文而有所不同。
推荐阅读
- python - 如何在pygame中伪造鼠标事件?
- behat - behat.yml 应该放在哪里
- ubuntu - 在 ubuntu 18.04 LTS 上安装 opendaylight 氟的问题
- django - Django REST 框架:如何在 POST 请求中与其他模型关联?
- python - How come the computer keeps accessing pythonw.exe file while creating environment?
- svg - SVG
用脚本改变所有 - javascript - 无法读取 null 的属性“cloneNode”,但当脚本在 HTML 上时有效
- javascript - JSP获取输入值
- php - 如何为 travis 构建测试创建作曲家
- excel - CopyFromRecordset 到 Excel 仅复制数字