ล่าสุดการพัฒนาเว็บบทเรียน
 

AngularJS NG-ตัวเลือกคำสั่ง


ตัวอย่าง

กรอกตัวเลือกในรายการแบบเลื่อนลงโดยใช้รายการของอาร์เรย์:

<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 สั่งเติม <เลือก> ด้วย <ตัวเลือก>

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
disabled when disable for value in array

label
group by group for value in array track by expression

label
disabled when disable for value in array track by expression

label
for value in array | orderBy expression track by expression