<select ng-model="machineSelected"
ng-options="machine._id as machine.name for machine in machineList"
ng-change="onChangeMachine(machineSelected)"
ng-disabled="!mineSelected">
<!--<option value=""></option>-->
<option value="">Select</option>
</select>
When I add
$scope.machineSelected = "";
dynamically wherever in the controller, option in drop-down should set as "Select", but it is not updating.
Use
null
orundefined
, not an empty string, as the "not selected" value.That's what the docs say:
It's not really clear that an empty string can't be used, but at least they mention
null
.Use
null
for the unselected value:The
ng-options
directive was re-factored with AngularJS V1.6. Before then the default could be selected with an empty string. Now the default is selected by assigningnull
to the model.For more infomation, see
select
withngOptions
and setting a default valueThe DEMO
Set default option in controller and dynamically change based on selected item
Controller