首页 文章

对话框不适用于有角度的材料

提问于
浏览
0

我试图使用角度材料 dialog . 我正在尝试实现页面上给出的第一个示例:Angular Material Dialog URL以下是上页给出的示例的Stackblitz URL:Example Mentioned on Angular material website

我所做的唯一修改是将对话框组件移动到一个单独的文件夹中 . 但是对话框没有正确打开,也没有显示数据 . 这是我工作的Stackblitz链接:My Implementation

我认为数据不会在对话框组件中传递 . 但我无法弄清楚原因 . 任何帮助将受到高度赞赏 .

2 回答

  • 5

    在Stackblitz中,控制台在单击按钮后显示有用的错误消息:

    ERROR
    Error: No component factory found for DialogComponentComponent. Did you add it 
    to @NgModule.entryComponents?
    

    要解决此问题,您需要将对话框中显示的组件添加到app.module.ts中的entryComponents集合(或Stackblitz中的main.ts文件):

    entryComponents: [DialogOverviewExample, DialogComponentComponent],

    这是必需的,因为对话框中显示的组件未通过组件在模板中引用's selector. Since Material' s对话框组件按类型引用显示的组件,Angular需要知道此组件仍需要加载并且在编译期间不会被树震掉 . Angular docs go into some additional detail on entryComponents if you're interested .

  • 1

    在main.ts中使用enrtyComponents声明它:

    ...
    entryComponents: [DialogOverviewExample, DialogComponentComponent],
    ...
    

    here is详细解释 .

相关问题