javascript - how to programmatically select an option as the selected option? -
i have html
<select class="form-control" name="settings.provider" id="settings.provider" ng-model="settings.provider" required> <option value="" disabled selected>select provider</option> <option value="thisprovider">thisprovider</option> </select>
how programmatically select "thisprovider" selected option?
i tried isn't working:
$scope.settings.provider = "thisprovider";
if options not bound ng-repeat, can bind each option setting in controller using ng-selected (https://docs.angularjs.org/api/ng/directive/ngselected). in controller, create boolean $scope.thisproviderselected each option, set true option want selected.
<select class="form-control" name="settings.provider" id="settings.provider" ng-model="settings.provider" required> <option value="" disabled selected>select provider</option> <option value="thisprovider" ng-selected="thisproviderselected">thisprovider</option> </select>
a better way use ng-repeat , add isselected each item in list. way if list changes, automatically new items.
Comments
Post a Comment