How to Restangularize Elements in a Collection from a Parent

I am returning an object using Restangular over AngularJS (the GPT object is the returned parent object), with the returned array, corresponding to projects with GPT.

I can do all the restatular things like save (), etc. on the parent GPT object. However, when I get a link to individual items in the "projects" collection, I cannot execute Restangular save (). How can I make sure that all elements returned in collections under the main object are "Restangularised" so that I can perform quiet operations on them? ie, I think I want a "deep Restangularisation", if that makes sense; -) ... if not, how can I Restangularize the instance before trying to perform the save () operation and provide the corresponding URL for PUT / POST, etc.

Hope this makes sense.

Hi

I am

+4
source share
1 answer

Restangular.restangularizeElement.

( ):

Restangular.one('courses', 123).get().then(function (course) {
  course.students = Restangular.restangularizeCollection(course, course.students, 'students');
  // You should now be able to do 'course.students[0].remove()'
  // And if you want to chain promises:
  return course;
});

+6

All Articles