首页 > 解决方案 > 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”

对检测问题的任何帮助都会有很大帮助。

标签: angularinternet-explorer-11

解决方案


根据文档,您需要实现IModalDialog并且需要dialogInitModalComponent.

从文档中检查这个例子

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
  }
}

推荐阅读