No component factory found for XXXComponent. Did you add it to @NgModule.entryComponents?

这个问题看了一个下午,在此提供一些解决方法。

感谢 https://github.com/angular/components/issues/1491 ,也建议各位能去看下这个讨论。

我的场景:

ActiveService中使用了modalServicemodalService在配置nzContent时用到了myActionComponent

即nzContent:myActionComponent;,此时控制台报错:

No component factory found for myActionComponent. Did you add it to @NgModule.entryComponents?

方案一:

在我当前所在的子模块的serviceXXX.module.ts文件中添加:

import { myActionComponent } from './xxx/active.service'
declarations: [
    myActionComponent,
]
entryComponents: [
    myActionComponent,
]

方案二:

上述无法解决的话可以用同样方法将同样的内容添加到app.module.ts中。

import { myActionComponent } from './xxx/active.service'
declarations: [
    myActionComponent,
]
entryComponents: [
    myActionComponent,
]

方案三:

app.module.ts中import serviceXXXModule

import { serviceXXXModule } from './xx/xx/xx/serviceXXX.module'

imports:[
    serviceXXXModule,
]

方案四:

serviceXXX.module.ts中import ActiveService:

import { ActiveService } from './xxx/active.service';

providers: [
    ActiveActionService,
],

 

你可能感兴趣的:(ANGULAR)