I have a key field that should be selected into a SELECT html element. This SELECT is populated with an ng-repeat.
I define two SELECTs, one with ng-repeat, other with ng-options:
<div ng-controller="MyDisplayCtrl">
<select ng-model="context.id1">
<option value="">-</option>
<option ng-repeat="i in lista" value="{{i.id}}">{{i.value}}</option>
</select> Should have "three" selected, but shows - <br/>
<select ng-model="context.id2" ng-options="i.value for i in lista">
</select> Selects "three" automatically <br/>
</div>
And my controller goes like this:
function MyDisplayCtrl($scope) {
var x1 = {id: 1, value: 'one'};
var x2 = {id: 2, value: 'two'};
var x3 = {id: 3, value: 'three'};
window.setTimeout(function() {
$scope.$apply(function() {
$scope.lista = [x1, x2, x3];
});
}, 2000);
$scope.context = {id1: 3, id2: x3};
}
I'd have this list brought to client by an AJAX, so I used a setTimeout() here.
The approach with ng-options works, but I wouldn't have an object, sole its key.
Take a look at this fiddle: http://jsfiddle.net/nCG2H/
Problem: I'm trying to understand why the first SELECT doesn't work, algo because I got it to work depending on timing from AJAX response.