0

我正在尝试使用 ag-grid 渲染组件,但出现此错误:

core.js:15713 ERROR 错误:没有为 squareRenderer 找到组件工厂。你把它添加到@NgModule.entryComponents 了吗?在 noComponentFactoryError (core.js:9875)

表.模块.ts

@NgModule({
    declarations: [SquareRenderer, ...containers, ...components],
    imports: [
    ...
        AgGridModule.withComponents([SquareRenderer]),
        ...
    ],
    entryComponents: [SquareRenderer],
    exports: [],
    providers: []
})
export class TableModule {}

表组件.ts

columnDefs = [
{
    headerName: '',
    children: [
      {
        headerName: 'Farm/Field',
        field: 'farm',
        width: 183,
        lockPosition: true,
        cellRendererFramework: 'squareRenderer'
        },
        ...
]
frameworkComponents = {
  squareRenderer: SquareRenderer
  };
}

HTML

<ag-grid-angular
        #agGrid
        style="width: 100%; height: 100%"
        class="ag-theme-balham"
        [columnDefs]="columnDefs"
        [defaultColDef]="defaultColDef"
        (gridReady)="onGridReady($event)"
        [cacheBlockSize]="cacheBlockSize"
        [infiniteInitialRowCount]="infiniteInitialRowCount"
        [rowModelType]="'infinite'"
        [maxBlocksInCache]="maxBlocksInCache"
        [frameworkComponents]="frameworkComponents"
        >
      </ag-grid-angular>

为什么我会收到此消息?我究竟做错了什么?

4

1 回答 1

0

转到您的 Angular 模块并将其添加到导入中

AgGridModule.withComponents([
  SquareRenderer
]),

并导入

import { AgGridModule } from 'ag-grid-angular';
于 2019-02-25T11:47:09.967 回答