角4:找不到组件工厂,您是否将其添加到@ NgModule.entryComponents? [英] Angular 4: no component factory found,did you add it to @NgModule.entryComponents?
问题描述
我正在将Angular 4模板与webpack一起使用 当我尝试使用组件(ConfirmComponent)时出现此错误:
I'm using Angular 4 template with webpack and I have this error when I try to use a component (ConfirmComponent):
没有为ConfirmComponent找到组件工厂.您是否将其添加到 @ NgModule.entryComponents?
No component factory found for ConfirmComponent. Did you add it to @NgModule.entryComponents?
该组件在app.module.server.ts
@NgModule({
bootstrap: [ AppComponent ],
imports: [
// ...
],
entryComponents: [
ConfirmComponent,
],
})
export class AppModule { }
我也有app.module.browser.ts
和app.module.shared.ts
我该如何解决?
推荐答案
将此添加到您的module.ts
,
declarations: [
AppComponent,
ConfirmComponent
]
如果ConfirmComponent在另一个模块中,则需要将其导出,以便可以在外部使用,请添加:
if ConfirmComponent is in another module, you need to export it there thus you can use it outside, add:
exports: [ ConfirmComponent ]
---显式启用Ivy更新Angular 9或Angular 8 ---
不再需要带有常春藤的条目组件,现在已弃用
---用于禁用了Ivy的Angular 9和8 ---
对于动态加载的组件,要生成ComponentFactory,还必须将该组件添加到模块的entryComponents中:
In the case of a dynamically loaded component and in order for a ComponentFactory to be generated, the component must also be added to the module’s entryComponents:
declarations: [
AppComponent,
ConfirmComponent
],
entryComponents: [ConfirmComponent],
根据entryComponents的定义
according to the definition of entryComponents
指定在定义此模块时应编译的组件列表.对于此处列出的每个组件,Angular将创建一个ComponentFactory并将其存储在ComponentFactoryResolver中.
Specifies a list of components that should be compiled when this module is defined. For each component listed here, Angular will create a ComponentFactory and store it in the ComponentFactoryResolver.
这篇关于角4:找不到组件工厂,您是否将其添加到@ NgModule.entryComponents?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!