代码之家  ›  专栏  ›  技术社区  ›  naspinski

如何创建动态组件作为参数-角度agGrid cellEditorFramework

  •  0
  • naspinski  · 技术社区  · 7 年前

    不确定这是否重要,但我使用agGrid,但它基本上是创建一个动态组件作为参数。这可以作为我的网格选项:

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

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

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

    但这给了我一个错误:

    找不到函数(params){的组件工厂。你加进去了吗

    角度4.4.6 聚合17.1.1

    1 回复  |  直到 7 年前
        1
  •  -1
  •   Denis Obydennykh    7 年前

    可以创建包裹角组件

    选择ExtWrapperComponent

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

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

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