AngularJS ng-optionsDirective
AngularJS Example
Populate a dropdown list using array elements:
<div ng-app="myApp" ng-controller="myCtrl">
<select ng-model="selectedName" ng-options="item for item in names"></select>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.names = ["Emil", "Tobias", "Linus"];
});
</script>
<select ng-model="selectedName" ng-options="item for item in names"></select>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.names = ["Emil", "Tobias", "Linus"];
});
</script>
Try it Yourself »
Definition and Usage
ng-optionsThe directive is used to populate the options of a <select> element using <options>.
ng-optionsThe directive uses an array to populate the dropdown list, and in most cases is used together withng-repeatthe directive.
Syntax
<select ng-options="array expression"></select>
The <details> element supports this directive.
Parameter Values
| Value | Description |
|---|---|
| array expression | An expression that fills the options for the select element from the array. |
Other Extensions
AngularJS Reference Manual