I have an array of elements which comes from a service, but I can't set a select option. the code goes like this..
"Model":
{
buses : [{
name: 'example1',
seats: '32',
license: '1234',
type : {
name: 'type1'
}
},{
name: 'example2',
seats: '31',
license: '123',
type : {
name: 'type2'
}
},{
name: 'example3',
seats: '33',
license: '1235',
type : {
name: 'type3'
}
}]
}
Controller
Dealer.getAll().then(function (dealers) {
$scope.allDealers = dealers.data;
});
View:
<tr ng-repeat="busT in dealer.buses track by $index">
<td>{{busT.name}}</td>
<td>
<select ng-options="bt.name for bt in busTypes" ng-model="dealer.buses[$index].type.name" >
</select>
</td>
<td>{{busT.seats}}</td>
<td>{{busT.license}}</td>
</tr>
the select should be set with what comes from the ajax call, since the template is a table for each row I want the bus type to be set in the select option that information is under buses[position].type.name, that is why I'm iterating over a tr, the ng-options are loading and showing correctly but the ng.model pointing to my dealer.buses is not reflecting what is there.
Here is a fiddle with the problem Fiddle