使用cellRendererFramework的ag-grid渲染组件抛出错误

时间:2019-02-25 09:08:43

标签: angular gridview ag-grid ag-grid-angular

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

  

core.js:15713错误错误:未找到以下组件的工厂   squareRenderer。您是否将其添加到@ NgModule.entryComponents?       在noComponentFactoryError(core.js:9875)

table.module.ts

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

table-component.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>

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

1 个答案:

答案 0 :(得分:0)

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

AgGridModule.withComponents([
  SquareRenderer
]),

并导入

import { AgGridModule } from 'ag-grid-angular';