1
我有4個組件。我使用KendoGrid來顯示所有四個組件中的數據。但現在,我不想用來在所有四個組件中設置KendoGrid。爲此,我創建了一個子組件,在該組件中設置KendoGrid並從父組件傳遞數據。角2:如何使我自己定製KendoGrid在角2
ChildComponent.ts:下面我的孩子分量被提供給
@Component({
selector:"my-kendo-grid",
template:`
<kendo-grid [data]="dataVal">
<template ngFor [ngForOf]="myArr" let-column >
<kendo-grid-column field="{{column}}" title="{{column}}" >
<template kendoCellTemplate let-dataItem>
<div>{{dataItem}}</div>
</template>
</kendo-grid-column>
</template>
</kendo-grid>
export class ChildComponent implements OnInit {
@Input() dataVal:any; //taking dataVal value from parent component
myArr=[];
ngOnInit({
this._usersService.getUsers().subscribe((userResponse: any)=> {
for (var key in userResponse[0]) {
this.myArr.push(key);
}
return this.myArr; // binding 'myArr' in Kendogrid template which is making the kendogrid header
});
}
})
}
而且我爲父級的一個樣子:
ParentComponent.html: 在此,我傳遞的gridView中的對象數組。
<my-kendo-grid [dataVal]="gridView"></my-kendo-grid>
現在,項目的輸出是:
標題是未來正確的,但在價值的地方,我收到的對象。
https://i.stack.imgur.com/L1RZt.png
請讓我知道自己做錯了什麼,我在這裏做什麼。