0

I have a select element with static options. The select use a ng-model, but when the model is set to one of the values of the options, it isn't selected.

Here is the HTML:

<select class="modal-textboxes" ng-model="vm.reportPresets.selectedPreset.systemWideAccess">
    <option value=false>User</option>
    <option value=true>System Wide</option>
</select>

When vm.reportPresets.selectedPreset.systemWideAccess equals true or false, none of the select options are selected.

1

2 Answers 2

0

You should use ngValue directive

(function(angular) {
  'use strict';
  angular.module('myApp', [])
    .controller('Controller', [function() {
      this.systemWideAccess = true;
    }]);

})(window.angular);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<div ng-app="myApp">
  <div ng-controller="Controller as vm">
    <select class="modal-textboxes" ng-model="vm.systemWideAccess">
        <option ng-value="false">User</option>
        <option ng-value="true">System Wide</option>
    </select>
  </div>
</div>

Sign up to request clarification or add additional context in comments.

Comments

0

I guess instead of putting the systemWideAccess as true just add an extra option

 <select class="modal-textboxes" ng-model="vm.systemWideAccess">
     <option ng-value="">--Select--</option>
     <option ng-value="false">User</option>
     <option ng-value="true">System Wide</option>
 </select>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.