Home>

Array method

Data is an array

$scope.years=[2014, 2015, 2016];

Page element

<select ng-model="item" ng-options="item as y for y in years">
 </select>

Set default

If you need to set the default options,You can set a parameter first:

$scope.item=2016;
$scope.years=[2014, 2015, 2016];

Object array method

Data is an array of objects

$scope.sites=[
 {site:"google", url:"https://www.google.com"}, {site:"163", url:"http://www.163.com"}, {site:"sina", url:"http://www.sina.com"}
];

Page element

<select ng-model="s.site" ng-options="s.site as s.site group by site.group for s in sites">
 </select>

Set default

If you need to set the default options,You can set a parameter first:

$scope.site="163";
$scope.sites=[
 {site:"google", url:"https://www.google.com"}, {site:"163", url:"http://www.163.com"}, {site:"sina", url:"http://www.sina.com"}
];

key-vules object array method

Data is an array of objects

$scope.cars={
car1:{brand:"byd", model:"y50", color:"red"},car2:{brand:"cc", model:"hf", color:"white"},car3:{brand:"jl", model:"jl10d", color:"black"}
};

Page element

<select ng-model="mycar" ng-options="y.brand for (x, y) in cars">
</select>

Set default

If you need to set the default options,You can set a parameter first:

$scope.site="byd";
$scope.cars={
car1:{brand:"byd", model:"y50", color:"red"},car2:{brand:"cc", model:"hf", color:"white"},car3:{brand:"jl", model:"jl10d", color:"black"}
};

angularjs ng-options official api

Array type:

label for value in array
select as label for value in array
label group by group for value in array
select as label group by group for value in array track by trackexpr

Object type:

label for (key, value) in object
select as label for (key, value) in object
label group by group for (key, value) in object
select as label group by group for (key, value) in ob
  • Previous C # enable transaction commit multiple SQL statement example code with parameters
  • Next idea2017 build jsp project and tomcat configuration tutorial
  • Trends