@Input()items
在child-component.ts
我们将它传递给之前如何使用/操作child-component.html
?如果控制台登录,我会得到空对象ngOnInit
子组件.ts
@Input()items: any[] = [];
父组件.html
<child-component [items]="items"></child-component>
父组件.ts
indexOrders() {
this.orderService
.indexOrders()
.subscribe(
(res) => {
this.items = res;
},
(err) => {
serviceHttpErrorHandler(err);
},
);
}
示例.json
传递给 this.item 的示例响应
[
{
"text":"wood",
"value":"100"
},
{
"text":"chair",
"value":"200"
},
{
"text":"board",
"value":"300"
}
]