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

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -