我正在运行for loop
内部行,并希望从 filterData 向value
字段分配数据。我不想动态地为数据分配数据。
<ion-row *ngFor="let type of filterData">
<ion-segment [(ngModel)]="selectedSegment" (ionChange)="onSegmentChanged($event)">
<ion-segment-button value="Must be came from *ngFor">
{{type.key}}
</ion-segment-button>
</ion-segment>
</ion-row>
filterData数组成立:
this.filterData=[
{"key":"Budget","value":"a1","type":"bar","labelid":"17"},
{"key":"Parking Capacity","value":"a2","type":"checkbox","labelid":"12"},
{"key":"Venue","value":"a3","type":"checkbox","labelid":"3"},
{"key":"No.of Rooms","value":"a4","type":"checkbox","labelid":"15"},
{"key":"Max.Capacity","value":"a5","type":"bar","labelid":"1"},
{"key":"Function Type","value":"a6","type":"checkbox","labelid":"11"}];
我想分配json
元素值字段中的值数据,但不能这样做。
有没有办法做到这一点?
答案 0 :(得分:2)
您可以ion-segment-button
或"value={{type.value}}"
将值绑定到[value]="type.value"
。
<ion-segment-button [value]="type.value">
{{type.key}}
</ion-segment-button>
<ion-segment-button value="{{type.value}}">
{{type.key}}
</ion-segment-button>
请参阅 working demo 。