ng-options
Diretiva AngularJS
Exemplo
Preencha as opções em uma lista suspensa usando os itens de uma matriz:
<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>
Definição e uso
A ng-options
diretiva preenche um elemento <select> com <options>.
A ng-options
diretiva usa uma matriz para preencher a lista suspensa. Em muitos casos, seria mais fácil usar a ng-repeat
diretiva, mas você tem mais flexibilidade ao usar a ng-options
diretiva.
Sintaxe
<select ng-options="array expression"></select>
Suportado pelo elemento <select>.
Valores de parâmetro
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 |