2017-03-02 53 views
0

如何显示从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> 

回答

0

对,你将需要一个包含50个变量的数组。

在您的模板中,使用ngFor循环访问您的数组,并为每个变量创建一个下拉列表并使用[(ngModel)]绑定数据。

让我知道如果你仍然无法弄清楚。

+0

嗨,谢谢你的帮助。 :) –