Chỉ thị ng-options
của AngularJS
Ví dụ
Điền các tùy chọn vào danh sách thả xuống bằng cách sử dụng các mục của một mả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>
Hãy tự mình thử »Định nghĩa và cách sử dụng
Lệnh ng-options
điền vào phần tử <select> bằng <options>.
Lệnh ng-options
sử dụng một mảng để điền vào danh sách thả xuống. Trong nhiều trường hợp, việc sử dụng lệnh ng-repeat
sẽ dễ dàng hơn nhưng bạn sẽ linh hoạt hơn khi sử dụng lệnh ng-options
.
Cú pháp
<select ng-options=" array expression "></select>
Được hỗ trợ bởi phần tử <select>.
Giá trị tham số
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 |