角度8:没有找到组件的组件工厂,即使在app.module.ts中也添加了

时间:2019-06-14 08:05:09

标签: ng-modules angular8

我正在尝试将项目从Angular 7迁移到Angular 8。

但是,升级到Angular 8后,出现HeaderComponent的以下错误。

zone.js:199未捕获的错误:找不到HeaderComp的组件工厂。您是否将其添加到@ NgModule.entryComponents?     在noComponentFactoryError(core.js:17988)     在CodegenComponentFactoryResolver.push ../ node_modules/@angular/core/fesm5/core.js.CodegenComponentFactoryResolver.resolveComponentFactory(core.js:18026)     在CodegenComponentFactoryResolver.push ../ node_modules/@angular/core/fesm5/core.js.CodegenComponentFactoryResolver.resolveComponentFactory(core.js:18023)     在AngularFrameworkComponentWrapper.push ../ node_modules / ag-grid-angular / dist / angularFrameworkComponentWrapper.js.AngularFrameworkComponentWrapper.createComponent(angularFrameworkComponentWrapper.js:65)处     在DynamicAgNg2Component.createComponent(angularFrameworkComponentWrapper.js:44)     在DynamicAgNg2Component.push ../ node_modules / ag-grid-angular / dist / angularFrameworkComponentWrapper.js.BaseGuiComponent.init(angularFrameworkComponentWrapper.js:84)     在DynamicAgNg2Component.init(angularFrameworkComponentWrapper.js:40)     在UserComponentFactory.push ../ node_modules / ag-grid-community / dist / lib / components / framework / userComponentFactory.js.UserComponentFactory.initComponent(userComponentFactory.js:371)上     在UserComponentFactory.push ../ node_modules / ag-grid-community / dist / lib / components / framework / userComponentFactory.js.UserComponentFactory.createAndInitUserComponent(userComponentFactory.js:121)     在UserComponentFactory.push ../ node_modules / ag-grid-community / dist / lib / components / framework / userComponentFactory.js.UserComponentFactory.newHeaderComponent(userComponentFactory.js:37)

请在下面找到HeaderComponent和app.module.ts。

这是针对Angular 8的,因此它可以在Angular 7中使用。在Google上搜索之后,我通过声明entryComponent改进了app.module.ts。

HeaderComponent.ts:

import { Component, OnInit, OnDestroy, Inject, forwardRef, Input } from 
'@angular/core';
import { pagesToggleService } from '../../services/toggler.service'
import { Subscriber } from 'rxjs/Subscriber'
declare var pg: any;
@Component({
selector: 'pg-header',
templateUrl: './header.component.html',
styleUrls: ['./header.component.scss']
})
export class HeaderComponent implements OnInit, OnDestroy {
_headerClass = "";
isHorizontalLayout: false;
_service;
@Input()
boxed: boolean = false;

@Input()
extraClass: string = "";

constructor(private toggler: pagesToggleService) {
}

ngOnInit() {
    this.isHorizontalLayout = pg.isHorizontalLayout;
    this._service = this.toggler.headerClass
        .subscribe(state => {
            this._headerClass = state;
        });
}

ngOnDestroy() {
    this._service.unsubscribe()
}
}

app.module.ts:

@NgModule({
declarations: [
  HeaderComponent
]

entryComponents: [
    HeaderComponent
]

我希望它可以在Angular 8中运行,但是会抛出“找不到HeaderComp的组件工厂”。错误。

请帮助我找到解决方案。

谢谢

亲切的问候。

2 个答案:

答案 0 :(得分:0)

在声明部分中,首先在app.module.ts中添加app组件,例如:

@NgModule({
declarations: [AppComponent,HeaderComponent],
entryComponents: [HeaderComponent]
})

谢谢

答案 1 :(得分:0)

错误提示说是HeadComp而不是HeaderComponent,所以这是一个网格问题,我通过使用html中的ngx-datatable对其进行了修复。