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 要素のオプションを埋めます。 |
其他扩展