Pete Tinkler Pete Tinkler - 4 months ago 23x
AngularJS Question

Restangular: why does post not update the collection?

Let's say I have the following...

myService = Restangular.all('things');
// success
function(things) {
$scope.things = things;
// failure
function(things) {
// do whatever, stuff failed

Now I have
which is a collection of
from the api, all well and good.

I want to post a new
, and return the promise so I can deal with the pass/fail elsewhere

return $ // A promise...

However, doing things this way DOESN'T automatically add my new
to the
collection. Why not? I've seen questions that link to the enhanced promises section of restangular docs and mention the "push" method, but that doesn't help me because
has no "push" method.

What's going on here? Where am I getting confused.


As mentionned in Restangular docs:

Because Restangular returns promises, we can then call methods on the returned data on promises so that we can run a function after the promise has completed. For instance, after we update a collection, we can then refresh the collection on our scope: {
  $scope.messages = messages.getList();
}, function error(reason) {
  // An error has occurred