angular - Angular4 模态对话框问题
问题描述
我正在使用 Angular 4。我试图在我的应用程序中使用ngx-modal-dialog
.
我使用的是 IE11 浏览器。下面是我的代码:
在 ParentPageComponent.ts 文件中,openNewDialog()
函数定义如下:
openNewDialog(){
this.modalService.openDialog
(
this.viewRef,
{
title: 'Some modal title',childComponent: SimpleModalComponent
}
);
}
ParentPageComponent.ts 文件的构造函数定义为
constructor(modalService: ModalDialogService, viewRef: ViewContainerRef){}
我entryComponents
在 app.module.ts 文件中添加了
entryComponents:[SimpleModalComponent]
我openNewDialog
从 ParentPageComponent.html 页面调用该函数。
openNewDialog
从父页面调用方法时,我无法弹出并收到以下错误。
TypeError:对象不支持属性或方法“dialogInit”
对检测问题的任何帮助都会有很大帮助。
解决方案
根据文档,您需要实现IModalDialog
并且需要dialogInit
在ModalComponent
.
从文档中检查这个例子
class MyModalComponent implements IModalDialog {
actionButtons: IModalDialogButton[];
constructor() {
this.actionButtons = [
{ text: 'Close' }, // no special processing here
{ text: 'I will always close', onAction: () => true },
{ text: 'I never close', onAction: () => false }
];
}
dialogInit(reference: ComponentRef<IModalDialog>, options: Partial<IModalDialogOptions<any>>) {
// no processing needed
}
}
推荐阅读
- javascript - 函数参数在循环内不起作用
- python - 无法终止由 win32com.client 启动的进程
- php - List all users and their recipes
- android - 如何在模拟器中手动设置 Android VM 堆大小?
- performance - 每秒处理 1,400,000 个订单和 1,400,000 个并发连接之间的差异
- matlab - MATLAB:用 NaN 替换每列的前导零
- python - Django - 覆盖保存方法以发送数据
- npm - 打包 React 应用时如何解决“Unexpected Token Operator (>)”错误?
- javascript - 渲染非常大的虚拟表的问题
- google-apps-script - 有没有办法使用 Apps 脚本获取网站的 IP