我正在使用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){}
我已将 app.module.ts 文件中的entryComponents
添加为
entryComponents:[SimpleModalComponent]
我正在从ParentPageComponent.html页面调用openNewDialog
函数。
从父页面调用该方法时,我无法打开弹出窗口并收到以下错误openNewDialog
。
类型错误:对象不支持属性或方法"dialogInit">
任何关于检测问题的帮助都将是很大的帮助。
根据文档,您需要实现IModalDialog
并且需要在ModalComponent
中定义dialogInit
。
从文档中检查此示例
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
}
}