How would I force ng-options to use selected value depending on ajax result
this one hold selectable values used to loop
$scope.selectOptions =
{
"api": "API",
"json": "JSON",
"xml": "XML",
"csv": "CSV"
};
feed holds returned ajax data and item.feed_type is the saved value which should be compared against $scope.selectOptions
<div ng-repeat="item in feed">
<select ng-model="formInfo.feed_type" ng-options="k as v for (k,v) in selectOptions" class="form-control">
</div>
You can do it like this using ngInit
to set formInfo.feed_type
value to item.feed_type
:
<div ng-repeat="item in feed" ng-init="formInfo.feed_type = item.feed_type">
<select ng-model="formInfo.feed_type" ng-options="k as v for (k,v) in selectOptions" class="form-control"></select>
</div>
Check the test demo: http://plnkr.co/edit/E1QsrY9XPSZnqXRJqHAJ?p=preview