Hi Jonathan,
Yes, if that is working, it’s indeed mostly luck. This is where you need to
build your own promise handler.
Something like this:
.factory('Utility', function($http) {
var self = this;
self.aList = []; //placeholder
self.reAssign = function (response) { //handle putting results into the
placeholder
// don't forget to handle error's in here!
self.aList = response.data;
};
// a function to enable refetching. it also uses the promise to
(re)populate the aList array.
self.reftech= function () {self.pList =
$http.get('getList.html').then(self.reAssign);} // kick off first time
loading! self.refetch(); return self; });
This will always return the promise, and the complete list. But it will
only fetch only once, after that, it will just return the resolved promise.
Doing this, you have the means to check if the list is fetched already (the
promise will be resolved/rejected), and the list itself readily
Available. This is similar to what ngResource does.
With kind regards
Sander
--
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.