Click here to Skip to main content
15,896,501 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi,
can anyone explain this code:
Given this array of items on the $scope:

$scope.items = [{
id: 1,
label: 'aLabel',
subItem: { name: 'aSubItem' }
}, {
id: 2,
label: 'bLabel',
subItem: { name: 'bSubItem' }
}];

<select ng-options="item as item.label for item in items track by item.id" ng-model="selected"></select>

In ng-options we have specified
"item as item.label for item in items track by item.id" can anyone explain this statement
Posted

I don't know Angular but I would guess it parses out to something like:
Select the item.label from the items array where the selected value matches the item.id
 
Share this answer
 
The explanation is already given in Angular Documentation.

https://docs.angularjs.org/api/ng/directive/ngOptions[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900