Angular4 + Material2, Dialog 异常 Exception


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 using ViewContainerRef.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 to entryComponents as well because router-outlet also uses ViewContainerRef.createComponent() to add routed components to the DOM.

So your code will be like

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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值