Angular 2 selectBox值
问题描述:
如何显示从selectBox
中选择的值。我无法使用ngModel
绑定属性,因为selectBox的数量正在动态变化。例如,我将有50个房间,因此每个selectBox
需要50个变量。有没有其他方式来做到这一点,或者我必须使用一组选定的值?这是我当前的代码:Angular 2 selectBox值
<tr *ngFor="let room of term.rooms">
<th>{{room.name}}</th>
<th><select #box><option *ngFor="let price of getPrices(room.id)" [ngValue]="price">{{price.name}}</option></select></th>
<th><!--ValueHere--></th><!--for example something like this price.value-->
</tr>
答
对,你将需要一个包含50个变量的数组。
在您的模板中,使用ngFor
循环访问您的数组,并为每个变量创建一个下拉列表并使用[(ngModel)]
绑定数据。
让我知道如果你仍然无法弄清楚。
嗨,谢谢你的帮助。 :) –