角 – 没有找到组件工厂.你有没有把它添加到@ NgModule.entryCom
发布时间:2020-12-17 17:43:15 所属栏目:安全 来源:网络整理
导读:在使用带有angular4的ag-grid时,我遇到了以下错误消息. 我试图通过HTTP获取json后显示行数据. this.gridOptions.api.setRowData(this.gridOptions.rowData); 但是我的代码在下面显示错误消息. ERROR Error: No component factory found for RedComponentComp
在使用带有angular4的ag-grid时,我遇到了以下错误消息.
我试图通过HTTP获取json后显示行数据. this.gridOptions.api.setRowData(this.gridOptions.rowData); 但是我的代码在下面显示错误消息.
这是我的app模块代码.我已经设置为entryComponents了. import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { FormsModule } from '@angular/forms'; import { HttpModule } from '@angular/http'; import { AgGridModule} from "ag-grid-angular/main"; import { AppComponent } from './app.component'; import { MyGridApplicationComponent } from './my-grid-application/my-grid-application.component'; import { RedComponentComponent } from './red-component/red-component.component'; @NgModule({ imports: [ BrowserModule,AgGridModule.withComponents( [RedComponentComponent] ),FormsModule,HttpModule ],declarations: [ AppComponent,MyGridApplicationComponent,RedComponentComponent ],entryComponents: [ RedComponentComponent ],providers: [],bootstrap: [AppComponent] }) export class AppModule { } error position of my code 我的问题.为什么此代码无法解析此组件. 解决方法
从服务器加载数据时,您将字符串传递给ComponentFactoryResolver,但它应该是组件类型.
header.json { "headerName": "DetailCode","field": "detailCode","cellRendererFramework": "RedComponentComponent",// string "width":100 }, 要解决它,我会创建入口组件映射,如: 入门components.ts import { RedComponentComponent } from './red-component/red-component.component'; export const entryComponentsMap = { 'RedComponentComponent': RedComponentComponent }; 然后将加载从json字符串映射到组件类 COMM-代码并网option.service.ts private fetchColumnDefs() { console.log("fetchColumnDefs()"); this.http.get(this.API_URI + "resident/header.json").subscribe( r => { this.gridOptions.columnDefs = r.json(); this.gridOptions.columnDefs.forEach((x: any) => { if (x.cellRendererFramework) { x.cellRendererFramework = entryComponentsMap[x.cellRendererFramework]; } }); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |