ng-options
Dyrektywa AngularJS
Przykład
Wypełnij opcje na liście rozwijanej za pomocą elementów tablicy:
<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>
Definicja i użycie
Dyrektywa ng-options
wypełnia element <select> z <options>.
Dyrektywa ng-options
używa tablicy do wypełnienia listy rozwijanej. W wielu przypadkach korzystanie z dyrektywy byłoby łatwiejsze ng-repeat
, ale jej użycie jest bardziej elastyczne ng-options
.
Składnia
<select ng-options="array expression"></select>
Obsługiwane przez element <select>.
Wartości parametrów
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 |