例
通過使用數組的項目填寫一個下拉列表中選擇:
<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 |