在我的代碼中,我列出了一些用戶記錄。有一列要更改produced by
該列存在一個下拉列表。我的ng-change
工作正常。在頁面刷新後,下拉列表中沒有填充上次我改變的內容。請檢查我的代碼 -如何默認選擇動態下拉?
身份
<select name="repeatSelect" id="repeatSelect" ng-model="model_produced_by" style="width: 62px;" ng-change="change_produced_by(model_produced_by, order.Order.id)">
<option value="">Select Produced By</option>
<option ng-repeat="option in produced_by.availableOptions" value="{{option.id}}" ng-selected="option.id == order.Order.assigned_to">{{option.name}}</option>
</select>
輸出 -
<select ng-change="change_produced_by(model_produced_by, order.Order.id)" style="width: 62px;" ng-model="model_produced_by" id="repeatSelect" name="repeatSelect" class="ng-pristine ng-valid ng-empty ng-touched">
<option value="">Select Produced By</option>
<option ng-selected="option.id == order.Order.assigned_to" value="1" ng-repeat="option in produced_by.availableOptions" class="ng-binding ng-scope">Outsourced</option>
<option ng-selected="option.id == order.Order.assigned_to" value="2" ng-repeat="option in produced_by.availableOptions" class="ng-binding ng-scope">In-House</option>
<option ng-selected="option.id == order.Order.assigned_to" value="3" ng-repeat="option in produced_by.availableOptions" class="ng-binding ng-scope">Local Store/Printer</option>
</select>
我要選擇值,它與option.id == order.Order.assigned_to
平等的,但我的代碼是行不通的。 此外,我在select
標記中使用了ng-init
。最後一個選項顯示在每個下拉菜單中。請檢查並告訴我錯誤在哪裏。
在選擇標記中,您使用了ng-model,其中應該存儲選定的值,並在每個選項中放置條件:ng-selected =「option.id == order.Order.assigned_to」。這似乎是不匹配的。 –