AngularJS Tutorial - ng-selected








We can use ng-selected to bind the presence or not of the selected attribute to the option tag.

Example

The following code shows how to ng-selected.


<!--   w  w  w.jav  a  2  s  .co m-->
<!doctype html>
<html ng-app="myApp">
<head>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.3/angular.js"></script>
</head>
<body>
  <input type="checkbox" ng-model="isB" >check me to select B</input><br/>
  <select>
    <option ng-selected="!isB">A</option>
    <option ng-selected="isB">B</option>
  </select>

  <script>
    angular.module('myApp', [])
  </script>

</body>
</html>

The code above is rendered as follows: