AngularJS ng-options 指令
AngularJS 實例
使用數組元素填充下拉列表:
< 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 >
< 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指令用於使用<options>填充<select>元素的選項。
ng-options指令使用數組來填充下拉列表,多數情況下與ng-repeat指令一起使用。
語法
< select ng-options= " array expression " > < /select >
<details> 元素支持該指令。
參數值
值 | 描述 |
---|---|
array expression | 數組中為select 元素填充選項的表達式。 |