微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

原文地址:https://www.jb51.cc/angularjs/146435.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐