加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Angular4 + Material2, Dialog 异常 Exception

发布时间:2020-12-17 08:58:54 所属栏目:安全 来源:网络整理
导读:Angular2 material dialog has issues - Did you add it to @NgModule.entryComponents? https://stackoverflow.com/questions/41519481/angular2-material-dialog-has-issues-did-you-add-it-to-ngmodule-entrycomponent 在项目里用到Material2的Dialog对话


Angular2 material dialog has issues - Did you add it to @NgModule.entryComponents?

https://stackoverflow.com/questions/41519481/angular2-material-dialog-has-issues-did-you-add-it-to-ngmodule-entrycomponent


在项目里用到Material2的Dialog对话框,按照官网的例子的正常流程写出的sample,当弹出dialog对话框时,对话框都不能正常显示,只在页面最左边显示,并且没有内容,好像是只弹出一个宽度为20px,高度为浏览器高度的一个对话框,并且浏览器console里提示如下,调查了好半天,还是对angular的

entryComponents
的属性不熟啊,解决方案如下:


stackoverflow给出的解决办法,

This is for dynamically added components that are added usingViewContainerRef.createComponent(). Adding them to entryComponents tells the offline template compiler to compile them and create factories for them.

The components registered in route configurations are added automatically toentryComponentsas well becauserouter-outletalso usesViewContainerRef.createComponent()to add routed components to the DOM.

So your code will be like

@NgModule({
  declarations: [
    AppComponent,LoginComponent,DashboardComponent,HomeComponent,DialogResultExampleDialog        
  ],entryComponents: [DialogResultExampleDialog]

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读