In my code, I have a list of user records. One column has a dropdown to change the produced by
. The ng-change
function is working fine. However, after refreshing the page, the dropdown does not show the last selected option. Please review my code below -
Identity
<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>
Output -
<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>
I want to select the value that matches
option.id == order.Order.assigned_to
, but it's not working.
I've also used ng-init
in the select
tag. The last option is appearing in every dropdown. Can you help me find the error?