restangular icon indicating copy to clipboard operation
restangular copied to clipboard

Chaining restangular from a service

Open pankajtandon opened this issue 13 years ago • 3 comments

Hi, I'd like to call a service from a controller. In the service, I want to make a Restangular call which returns a promise, massage the returned data in the success callback, and then pass back the promise to the controller where I would assign the hopefully massaged data to a variable on the $scope.

I wrote a plunkr here http://plnkr.co/edit/7Ir9K3?p=preview

to do this, but it does not work. Even tho Restangular returns the correct data, and I can massage it in the service, what I get back in the controller is NOT the massaged object but a Restangularized object.

Is this the right way to chain promises in restangular?

Thanks a lot for your help and for a great project!

pankajtandon avatar Sep 28 '13 02:09 pankajtandon

Hey,

I've seen the plunkr but I don't completely understand your point. I do see that when you're using the service, the firstName is correctly changed when using it in the controller, so you're setting the massaged data in the controller. What's your problem here?

Thanks!

mgonto avatar Sep 30 '13 20:09 mgonto

Hi, I'm sorry, I wrote that plunker in a hurry and did not annotate it correctly. I've fixed it now: http://plnkr.co/edit/7Ir9K3?p=preview And after I did that, I realized I was wasting your time :) Sorry about that!

pankajtandon avatar Oct 01 '13 00:10 pankajtandon

Haha no problem :)

Glad to help!

mgonto avatar Oct 01 '13 02:10 mgonto