I have a data service that says:
myApp.factory('locationsData', function ($resource) {
return $resource('/api/Location/:id', { id: '@id' }, { update: { method: 'PUT' } });});
I then use these locations to populate a dropdown in my view:
<select ng-model="locationId" ng-options="item.LocationId as item.LocationName for item in locations"></select>
I want to set the init value of the dropdown in my controller with:
$scope.locationId = 8;
This doesn't work, i think because of the async nature of $resource -- it doesn't have the list yet so i can't set it.
I know $q is designed to address this, but not sure on how to create the promise, and set
$scope.locationId = 8;
after it is fulfilled
I've read the $q and $resource documentation, but i have yet to see a good code sample of how one would do a simple get like i'm doing, and then execute some function/action after the get promise is fulfilled.
Thanks.