ng-optionsSměrnice AngularJS


Příklad

Vyplňte možnosti v rozevíracím seznamu pomocí položek pole:

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

Definice a použití

Direktiva ng-optionsvyplní prvek <select> pomocí <options>.

Direktiva ng-optionspoužívá pole k vyplnění rozevíracího seznamu. V mnoha případech by bylo jednodušší použít ng-repeat směrnici, ale při používání směrnice máte větší flexibilitu ng-options .


Syntax

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

Podporováno prvkem <select>.


Hodnoty parametrů

Value Description
array expression An expression that selects the specified parts of an array to fill the select element.

Legal 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