将参数传递给子组件 Angular
Pass parameter to child component Angular
当我将对象从父组件传递给子组件时 - 它被转换为字符串
<m-tank-add fuelTypes="{{this.fuelTypes}}" count="{{count}}"></m-tank-add>
@Input() fuelTypes: Array<FuelTypeModel>;
@Input() count: number;
count
作为 "5"
而 fuelTypes
作为 "[object Object],[object Object],[object Object],[object Object],[object Object]"
如何传递参数以免它们被转换为字符串?
您应该使用 属性 通过方括号绑定,因为 with 插值被字符串化:
[fuelTypes]="fuelTypes"
另请参阅:
- string interpolation in angular 2 and it's dynamicity
当我将对象从父组件传递给子组件时 - 它被转换为字符串
<m-tank-add fuelTypes="{{this.fuelTypes}}" count="{{count}}"></m-tank-add>
@Input() fuelTypes: Array<FuelTypeModel>;
@Input() count: number;
count
作为 "5"
而 fuelTypes
作为 "[object Object],[object Object],[object Object],[object Object],[object Object]"
如何传递参数以免它们被转换为字符串?
您应该使用 属性 通过方括号绑定,因为 with 插值被字符串化:
[fuelTypes]="fuelTypes"
另请参阅:
- string interpolation in angular 2 and it's dynamicity