Angular 2 Kendo UI 将列定义从父组件传递到网格

Angular 2 Kendo UI pass column definitions to grid from parent component

我目前正在使用 Angular 4 和 Kendo UI 用于 Angular 的项目。 我们有多个 kendo 应使用相同配置的网格。(工具栏、分页、页脚模板,...)

我决定为我们的网格制作一个具有默认配置的组件,这样我们就不会在所有地方使用相同的代码。

所有网格之间的主要区别在于列定义。所以我的想法是将它们作为内容传递给我的包装器组件,并在我的 kendo 网格中添加 ng-content。

所以我现在拥有的是:
main.component.ts

@Component({
    template: "<grid-wrapper>
                   <kendo-grid-column field="projectName">
                       <ng-template kendoGridHeaderTemplate>
                           <span>Project Name</span>
                       </ng-template>
                   </kendo-grid-column>
               </grid-wrapper>"
})
export class MainComponent {
}

wrapper.component.ts

@Component({
    template: "<div>
                   <!-- Some code for buttons shown above the grid -->
                   <kendo-grid [data]="data"
                               [pageSize]="pageSize"
                               [sortable]="{mode: 'single'}"
                       <ng-content></ng-content>
                       <!-- templates and components for paging, toolbar, ... -->
                   </kendo-grid>
               </div>",
    selector: "grid-wrapper"
})
export class WrapperComponent {
    private data: GridDataResult;
    private pageSize: number = 10;

    // ...
    // Some code for filling the data
    // ...
}

调试 kendo 网格时,我注意到 GridComponent 使用 @ContentChildren 获取列,但此集合为空。

有人知道出了什么问题吗?或者关于如何做得更好的任何建议?

此致, BillieTK.

在 :

得到了答案

看看那里显示的 plunker。 对我有用!! GridComponent 使用 ContentChildren 来 select 定义的列,这不适用于包含。一种可能的解决方法 - plnkr.co/edit/w6EgmZL5z8J6CvpjMl2h?p=preview – rusev 1 月 5 日 8:51