pfried pfried - 5 months ago 17
AngularJS Question

Restangular inserting models to collection after post

I am inserting a model in a restangular collection with post

var collectionService = restAngular.all('collection');
var collection = collectionService.getList();

var item = {
title : "A title"
};

collection.post(item);


Now i could do instead of the last statement:

collection.post(item).then(function(newItem) {
collection.push(newItem);
});


Why is the inserted model not inserted into the collection by default? Is there a reason for this? Am i missing a call or something? I would like to avoid fetching the collection again after i inserted the model

Answer

From the docs https://github.com/mgonto/restangular#enhanced-promises

Try

collection.call("push", newItem);

Also, make sure that newItem is really being returned correctly.

Comments