AngularJS 实例
使用数组元素填充下拉列表:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
<!DOCTYPE html>
<html>
<head>
<meta charset=
"utf-8"
>
<script src=
"http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"
></script>
</head>
<body>
<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>
<p>该实例演示了如何使用 ng-options 指令填充下拉列表。</p>
</body>
</html>
|
定义和用法
ng-options 指令用于使用 <options> 填充 <select> 元素的选项。
ng-options 指令使用数组来填充下拉列表,多数情况下与 ng-repeat 指令一起使用。
语法
<select ng-options="array expression"></select>
<details> 元素支持该指令。
参数值
值 | 描述 |
---|---|
array expression | 数组中为 select 元素填充选项的表达式。 |