我有一个界面:
export interface ItemResponse {
get: Array<Item>;
sent: Array<Item>;
}
我在组件中有一些代码:
itemData: ItemResponse;
ngOnInit() {
this.getItems();
}
getItems(){
this.itemService.getallItem().subscribe(data => {
this.itemData = data;
});
}
模板部分:
<item-table [data]="itemData.get"></item-table>
我需要多次使用角度材料表,因此我为此创建了一个组件。一个想要传递数据源,但我得到下一个错误:
ItemComponent.html:5 ERROR TypeError: Cannot read property 'get' of undefined
at Object.eval [as updateDirectives] (ItemComponent.html:11)
at Object.debugUpdateDirectives [as updateDirectives] (core.js:30537)
at checkAndUpdateView (core.js:29933)
at callViewaction (core.js:30174)
at execComponentViewsaction (core.js:30116)
at checkAndUpdateView (core.js:29939)
at callViewaction (core.js:30174)
at execEmbeddedViewsaction (core.js:30137)
at checkAndUpdateView (core.js:29934)
at callViewaction (core.js:30174)
我应该如何声明此属性?我尝试了很多方法,例如:
itemData = {get: [],sent:[]} as ItemResponse;
在这种情况下,itemData.get
不是未定义的,但是它是空的。
您有什么想法,我该怎么办?对不起语法错误,英语不是我的母语。