Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 4:未找到组件工厂,是否已将其添加到@NgModule.entryComponents?_Angular_Angular Webpack Starter - Fatal编程技术网

Angular 4:未找到组件工厂,是否已将其添加到@NgModule.entryComponents?

Angular 4:未找到组件工厂,是否已将其添加到@NgModule.entryComponents?,angular,angular-webpack-starter,Angular,Angular Webpack Starter,我正在使用带有网页的Angular 4模板 当我尝试使用一个组件(ConfirmComponent)时,出现了这个错误: 未找到ConfirmComponent的组件工厂。你把它加进去了吗 @NgModule.entryComponents 组件在app.module.server.ts中声明 @NgModule({ 引导:[AppComponent], 进口:[ // ... ], 入口组件:[ 确认组件, ], }) 导出类AppModule{} 我还有app.module.browser

我正在使用带有网页的Angular 4模板 当我尝试使用一个组件(ConfirmComponent)时,出现了这个错误:

未找到ConfirmComponent的组件工厂。你把它加进去了吗 @NgModule.entryComponents

组件在app.module.server.ts中声明

@NgModule({
引导:[AppComponent],
进口:[
// ...
],
入口组件:[
确认组件,
],
})
导出类AppModule{}
我还有
app.module.browser.ts
app.module.shared.ts


如何修复此问题?

将其添加到
模块.ts中

声明:[
应用组件,
确认组件
]

如果ConfirmComponent位于另一个模块中,则需要将其导出到该模块中,以便在外部使用,添加:

导出:[ConfirmComponent]
——显式启用常春藤更新Angular 9或Angular 8---

不再需要带有常春藤的入门级组件,现在已弃用

——对于禁用常春藤的有角度的9号和8号---

对于动态加载的组件,为了生成ComponentFactory,还必须将该组件添加到模块的entryComponents中:

声明:[
应用组件,
确认组件
],
entryComponents:[确认组件],
根据entryComponents的定义

指定定义此模块时应编译的组件列表。对于此处列出的每个组件,Angular将创建一个ComponentFactory并将其存储在ComponentFactoryResolver中


如果在应用程序中使用路由

确保将新组件添加到布线路径中

例如:

    const appRoutes: Routes = [
  { path: '', component: LoginComponent },
  { path: 'home', component: HomeComponent },
  { path: 'fundList',      component: FundListComponent },
];

我也有同样的问题。在这种情况下,
imports[…]
至关重要,因为如果不导入
NgbModalModule
,它将无法工作

错误描述指出组件应该添加到
entryComponents
数组中,这一点很明显,但请确保您首先添加了此组件:

imports: [
    ...
    NgbModalModule,
    ...
  ],

TL;DR:当组件未添加到app.module的
entryComponents
中时,在“root”
中提供了
的ng6中的服务找不到组件工厂

如果将angular 6与在服务中动态创建组件结合使用,也会出现此问题

例如,创建覆盖:

@可注入({
提供于:“根”
})
导出类覆盖服务{
构造函数(私有_overlay:overlay){}
openOverlay(){
const overlayRef=this._createOverlay();
const portal=新组件门户(OverlayExampleComponent);
overlayRef.attach(portal.instance);
}
}
问题在于

提供于:“根”

定义,它在app.module中提供此服务


因此,如果您的服务位于例如“OverlyModule”中,您也在其中声明了OverlyExampleComponent并将其添加到entryComponents中,则服务无法找到OverlyExampleComponent的组件工厂。

将该组件添加到应用程序模块的@NgModule中的entryComponents中:

entryComponents:[ConfirmComponent],
以及声明:

declarations: [
    AppComponent,
    ConfirmComponent
]

将动态创建的组件放置到entryComponents 在@ngmodulecorator函数下

@NgModule({
    imports: [
        FormsModule,
        CommonModule,
        DashbaordRoutingModule
    ],
    declarations: [
        MainComponent,
        TestDialog
    ],
    entryComponents: [
        TestDialog
    ]
})

我对引导模式也有同样的问题

从'@ng bootstrap/ng bootstrap'导入{NgbModal}

如果这是您的情况,只需按照其他响应的建议将组件添加到模块声明和entryComponents中,也可以将其添加到您的模块中

从'@ng bootstrap/ng bootstrap'导入{NgbModule}

关于
entryComponent

如果要动态加载任何组件,则需要将其放入
声明
入口组件

@NgModule({
进口:[……],
出口:[……],
entryComponents:[确认组件,…],
声明:[ConfirmComponent,…],
提供者:[……]
})

我对angular 6也有同样的问题, 这就是我的工作原理:

@NgModule({
...
entryComponents: [ConfirmComponent],
providers:[ConfirmService]

})

如果你有一个像ConfirmService这样的服务,必须在当前模块的提供者中声明,而不是在根目录中声明。在我的情况下,我根本不需要entryComponents,只需要下面链接中描述的基本设置,但我需要在主应用程序模块和封装模块中包含导入

imports: [
    NgbModule.forRoot(),
    ...
]

如果某个组件将包含在模式中,则只需将其添加到entryComponents。从文档中:

可以将现有组件作为模式窗口的内容传递。在里面 本例中,请记住将内容组件添加为entryComponents 您的模块的第节


使用动态组件的ag grid也遇到了同样的问题。我发现您需要将动态组件添加到ag网格模块中。withComponents[]

进口:[ 层材料模块, 浏览器模块, 批准模块, HttpClientModule, BrowserAnimationsModule, NgbModule.forRoot(), FormsModule, 反应形式模块, 批准模块, AgGridModule.withComponents(项目更新按钮组件)
],

在创建动态组件时,我在Angular7中遇到了同样的问题。有两个组件(TreatListComponent、MyTreatComponent)需要动态加载。我刚刚在app.module.ts文件中添加了entryComponents数组

    entryComponents: [
    TreatListComponent,
    MyTreatComponent
  ],

尝试动态加载组件时会发生此错误,并且:

  • 要加载的组件不是路由模块
  • 该组件不在模块entryComponents中
  • 路由模块内

    const routes: Routes = [{ path: 'confirm-component', component: ConfirmComponent,data: {}}]
    
    或在模块中

    entryComponents: [
    ConfirmComponent
    } 
    
    要修复此错误,您可以将路由器添加到组件或将其添加到模块的entryComponents

  • 将路由器添加到组件。这种方法的缺点是 组件将可以通过该url访问
  • 加上
    entryComponents: [
    ConfirmComponent
    } 
    
    imports: [
        ...
        TheModuleThatOwnTheTargetedComponent,
        ...
      ],
    
    declarations: [
        AppComponent,
        ExampleDialogComponent
      ],
    
      entryComponents: [
        ExampleDialogComponent
      ],
    
     entryComponents: [
    CityModalComponent
    ],
    
      "angularCompilerOptions": {
        "enableIvy": false
      }