So I've pretty much got to grips with the whole promise, defer concept but
I'm struggling with a couple of final hurdles.
My factory is working fine and querying an external rest service without
issues
.factory('GetData', ['$resource',
function($resource){
return $resource('http://my-rest-server/rest/ml-sql/country_locations',
{}, {
query: {
method:'GET',
isArray:false
}
})
}])
In my controller I'm injecting the service and successfully loading it
however I have an issue in that init needs to run after all the data has
been returned from the service [it won;t work unless the data is available
up front].
I've managed to implement a very dirty hack whereby I just delay the
function using $timeout which gives the data time to load. While this works
I know it isn't a solution as the time required could vary massively, it
needs to be resolved prior to running.
I think I'm pretty close I just don't know how to complete the final step.
Any pointers would be much appreciated.
$scope.locations = GetData.query();
var init;
init = function() {
//do some stuff
};
var defer = $q.defer();
defer.promise
.then(function () {
init();
});
$timeout(function() {
defer.resolve();
}, 1000);
Many thanks
Antony
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.