例
通过使用数组的项目填写一个下拉列表中选择:
<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>
试一试» 定义和用法
该ng-options
指令填满了<选项>在<select>元素。
该ng-options
指令使用数组来填充下拉列表。 在许多情况下,它会更容易使用ng-repeat
指令,但您在使用时有更多的灵活性ng-options
指令。
句法
<select ng-options=" array expression "></select>
由<select>元素的支持。
参数值
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 disabled when disable for value in array label group by group for value in array track by expression label disabled when disable for value in array track by expression label for value in array | orderBy expression track by expression |