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>
ความหมายและการใช้งาน
คำng-options
สั่งเติม <select> องค์ประกอบด้วย <options>
คำ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 disable when disable for value in array label group by group for value in array track by expression label disable when disable for value in array track by expression label for value in array | orderBy expression track by expression |