gpt4 book ai didi

Angular 4 : no component factory found, 你把它添加到@NgModule.entryComponents了吗?

转载 作者:太空狗 更新时间:2023-10-29 16:44:14 25 4
gpt4 key购买 nike

我在 webpack 中使用 Angular 4 模板当我尝试使用组件 (ConfirmComponent) 时出现此错误:

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.tsapp.module.shared.ts

我该如何解决?

最佳答案

将此添加到您的 module.ts

declarations: [
AppComponent,
ConfirmComponent
]

如果ConfirmComponent在另一个模块中,你需要将它导出到那里以便你可以在外面使用它,添加:

exports: [ ConfirmComponent ]

---明确启用 Ivy 更新 Angular 9 或 Angular 8---

不再需要使用 Ivy 的入口组件,现在已弃用

---对于禁用了 Ivy 的 Angular 9 和 8---

在动态加载组件的情况下,为了生成 ComponentFactory,还必须将组件添加到模块的 entryComponents 中:

declarations: [
AppComponent,
ConfirmComponent
],
entryComponents: [ConfirmComponent],

根据entryComponents的定义

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.

关于Angular 4 : no component factory found, 你把它添加到@NgModule.entryComponents了吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46990389/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com