How do ng-options and ng-repeat differ?
In the following code, I have an ng-repeat that iterates through a list of people:
From the documentation:
Note: ngOptions provides an iterator facility for the element which should be used instead of ngRepeat when you want the select model to be bound to a non-string value. This is because an option element can only be bound to string values at present.
This fiddle makes the point more clear: select2 will bind to select 1 but not the other way around. Click the buttons and the reason will reveal itself :-)
HTML
selected: {{selectedPerson}} {{typeofSelectedPerson()}}
JS
function MyCtrl($scope){
$scope.selectedPerson = 1;
$scope.people = [
{
id: 1,
name: 'Ze'
},
{
id: 2,
name: 'Jao'
}
];
$scope.typeofSelectedPerson = function(){
return typeof $scope.selectedPerson;
}
}