如何创建动态组件作为参数-angular aGridGrid cellEditorFramework

时间:2018-09-25 14:44:12

标签: angularjs angular ag-grid angular-components

不确定是否重要,但是我正在使用agGrid,但它基本上是在创建动态组件作为参数。可以像我的GridOptions一样正常工作:

...
children: [
    ...
    cellEditorFramework: SelectCellComponent,
    ...
]
...

但是如果我想做一个条件编辑器怎么办?像这样:

...
children: [
    ...
    cellEditorFramework: (params) => {
        return params.type === 'Select' ? SelectCellComponent : TextCellComponent
    },
    ...
]
...

但这给了我错误:

  

未找到功能(参数){的组件工厂。您是否将其添加到   @ NgModule.entryComponents?

有没有办法做到这一点?

角4.4.6 agGrid 17.1.1

1 个答案:

答案 0 :(得分:-1)

您可以创建环绕角分量

SelectOrTextWrapperComponent

...
children: [
    ...
    cellEditorFramework: SelectOrTextWrapperComponent,
    ...
]
...

在运行时内部决定要显示的内容-选择还是文本

<select-cell *ngIf="params.type == 'select'"></select-cell>
<text-cell *ngIf="params.type != 'select'"></text-cell>