2017-03-02 54 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

嗨,謝謝你的幫助。 :) –