Hello,

I am at a loss how to retrieve data from a service to a controller using 
promises. The controller calls a function on the dataservice, that in turns 
makes a REST $http.get() call and returns a promise to the controller. When 
the promise gets resolved the .success() function gets executed in the 
context of the controller and the data is assigned to an array that in turn 
is assigned to a $scope key.

That works fine.

BUT since the promise chain ends in the controller, whenever I change state 
(I use the ui-router), the next time I get back to the controller, the data 
is retrieved and is assigned to a new _empty_ array instread of the array 
with data I retrieved previously. This is a problem since I need to _add_ 
that new data to the previously retrieved data. 

As in a shopping cart where each time when I enter the controller with a 
articleID a new product has to be retrieved by the DataService and added to 
the array.
Since I keep the data array in the controller and the controller is 
destroyed at every state change I effectivelty only have 1 article in my 
list - the current article. I never add to an existing array of articles

How can I solve this - using $http promises? I guess I need to store the 
data in a service (Singleton) but then how do I return asynchrounously data 
to the controller? 

-- 
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.

Reply via email to