AngularJS ng-options 指令
AngularJS 實例
使用數組元素填充下拉列表:
<!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 元素填充選項的表達式。 |
以上就是對AngularJS ng-options資料的整理,后續繼續補充。
新聞熱點
疑難解答