Note: I also posted this question on the AngularJS mailing list here: https://groups.google.com/forum/#!topic/angular/UC8_pZsdn2U
Hi All,
I\'m building my fi
Ok..so looks like I solved the problem by passing a callback function all the way up to the resource.query() call. Still not sure if this is the best way to do this.
For reference, this is what I did:
CountryController:
$scope.countries = CountryService.getCountries(function(){
//preselected default
$scope.selected.country = $scope.countries[0];
});
CountryService:
//Country Service. Will contain all relevant rest methods here
services.factory('CountryService', function($resource) {
var countryService = {};
var data;
var resource = $resource('http://localhost:port/restwrapper/country.json', {port: ':8080'});
var countries = function(callback) {
data = resource.query(callback);
return data;
}
return {
getCountries: function(callback) {
if(data) {
console.log("returning cached data");
return data;
} else {
console.log("getting countries from server");
return countries(callback);
}
}
};
});