AngularJS ng-options คำสั่ง

การใช้งานและการประกาศ

ng-options คำสั่ง <options> บรรจุ lt;select> ตัวแปร

ng-options คำสั่งใช้ตัวแปรแบบนี้เพื่อบรรจุรายการในรายการตัวเลือก ในหลายกรณี ใช้ ng-repeat คำสั่งจะง่ายขึ้น แต่ใช้ ng-options มีความยอมรับสูงขึ้นเมื่อใช้คำสั่ง

ตัวอย่าง

ผ่านการใช้รายการในตัวแปรแบบนี้เพื่อบรรจุค่าในรายการตัวเลือก:

<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-options="array expression"></select>

ติดตาม <select> เศษส่วนที่สนับสนุน

ตัวแปร

ตัวแปร รายละเอียด
array expression

expression ที่เลือกช่วงส่วนใด ๆ ของตัวแปร array ในการกรองตัวแปรของ element select

กล่าวว่า expression ที่ถูกต้อง

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