ng-select

Description

ng-select directive binds data to an HTML <select> element.

ng-options can take an object array and get its contents for the option select tag.

It comes in one of the following forms:

  • for array data sources:
    • label for value in array
    • select as label for value in array
    • label group by group for value in array
    • select as label group by group for value in array track by trackexpr
  • for object data sources:
    • label for (key, value) in object
    • select as label for (key, value) in object
    • label group by group for (key, value) in object
    • select as label group by group for (key, value) in object

Example

The following code shows how to ng-select.


<!--  w  ww.  j a v a  2s .c  o  m-->
<!doctype html>
<html ng-app="myApp">
<head>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.2/angular.js"></script>
</head>
<body>

  <div ng-controller="MyController">
    <select ng-model="myValue" ng-options="myValue.name for myValue in myValues">
      <option value="">Choose a Value</option>
    </select>
    {{ myValue.name }}
  </div>


  <script>
    angular.module('myApp', [])
    .controller('MyController', function($scope) {
        $scope.myValues = [
          {name: 'A'},
          {name: 'B'},
          {name: 'C'},
          {name: 'D'},
          {name: 'E'}
        ];
    });
  </script>

</body>
</html>

Click to view the demo





















Home »
  AngularJS »
    AngularJS Tutorial »




Introduction
Buildin Filters
Buildin Directives