AngularJS ng-options Directive

Definition and Usage

ng-options The directive uses <options> fill lt;select> elements.

ng-options directives use arrays to fill in dropdown lists. In many cases, using ng-repeat directives make it easier, but using ng-options you have more flexibility when using directives.

Example

Fill in the options in the dropdown list using items from the array:

<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>

Try It Yourself

Syntax

<select ng-options="array expression"></select>

Affected <select> Element Support.

Parameters

Parameters Description
array expression

An expression that selects a specified part of the array to fill the select element.

Valid expressions:

label for value in array

select as label for value in array

label group by group for value in array

label disable when disable for value in array

label group by group for value in array track by expression

label disable when disable for value in array track by expression

label for value in array | orderBy expression track by expression