我的问题是,如何将项的数组作为数据绑定值传递?
在我的例子中,我通过@input()给我的Angular 组件提供了一个IValuearray.
但是,当我判断应该接收数组的@input()变量时,它只是打印出一个对象数组,而不是IValue数组,尽管我给它的类型是IValues.
Component (FoodListPage) with data:个
export class FoodListPage implements OnInit {
foods: IValues[]; // <-- My data to pass
category: string;
constructor(private router: Router) {
this.category = this.router.getCurrentNavigation().extras.state.categoryName;
this.foods = this.router.getCurrentNavigation().extras.state.values;
console.log("food-list-data: ", this.foods);
}
ngOnInit() {}
}
The html of the component FoodListPage个
<ion-content>
<app-header title="{{category}}"></app-header>
<app-food-listing values="{{foods}}"></app-food-listing> <!-- Here I pass the value (array of IValues) -->
<app-nav-button page="main-menu"></app-nav-button>
</ion-content>
FoodListingComponent that should receive the value (array of IValues)个
export class FoodListingComponent implements OnInit {
@Input() values: IValues[];
constructor() { }
ngOnInit() {
console.log("food-listing-data: ", this.values); //Console log (actual)
}
}
预期数据:(4)[{…},{…},{…},{…}]<;--都来自类型IValue
实际数据:[OBJECT OBJECT],[OBJECT OBJECT]<;--仅来自类型"Object"...