restangular icon indicating copy to clipboard operation
restangular copied to clipboard

No examples of how to use use restangularizeElement

Open WillsB3 opened this issue 11 years ago • 11 comments

Hi,

I'm using Restangular in a project where I have a Tag resource, and each Tag resource has an array of TagInstances. I think I need to manually Restangularize the TagInstances once the Tag response comes back, but there are no examples of how to use this method in the documentation.

Could we get an/some examples added?

WillsB3 avatar Nov 25 '14 08:11 WillsB3

To add restangularizeCollection with array examples as well.

grabbou avatar Feb 22 '15 12:02 grabbou

+1

ghost avatar Jun 03 '15 21:06 ghost

+1. Would be great to see some documentation

borisano avatar Jun 24 '15 13:06 borisano

:+1:

augnustin avatar Jul 17 '15 10:07 augnustin

+1

mohsinkerai avatar Dec 23 '15 06:12 mohsinkerai

+1

rguruprakash avatar May 11 '16 03:05 rguruprakash

Would especially love to see the first parameter explained.

bitflower avatar May 11 '16 14:05 bitflower

@WillsB3 There is a section that documents restangularizeElement. Is there something else that needs clarifying? Other than the first parameter (see next paragraph), it's pretty clear?

I do agree with @bitflower; it would be nice to have documentation on the first parameter

daviesgeek avatar May 11 '16 16:05 daviesgeek

+1. The method is in the source code here (link is latest commit on master): https://github.com/mgonto/restangular/blob/b21e357ae6f4092d12cda2f6456f299d90b1e922/dist/restangular.js#L956

wayspurrchen avatar May 13 '16 21:05 wayspurrchen

That is correct. I wouldn't mind seeing a PR to explain this more in depth in the documentation

daviesgeek avatar Jun 16 '16 21:06 daviesgeek

I'll post this here, because this is where Google is sending people looking for help.

restangularizeElement(parent, element, route, queryParams): Restangularizes a new element

"parent" is a Restangular object or null if there is no parent. Given the REST route /accounts/123/buildings/123 the buildings object has accounts as a Restangular parent object. So if you had to serialize the buildings object and wanted to maintain the parent you would pass the accounts instance as the parent.

"element" is a JavaScript object with properties that you want to be a Restangular object. The object should have an ID if it has already been created.

"queryParams" the same as the get and post methods for adding extra query arguments (can be skipped).

Here is an example:

   var data = {id:3,title:"Something"};
   var document = Restangular.restangularizeElement(null, {id:3,title:"Something"}, 'documents')

This would create a document object that has an ID or 3 and title of "Something" and supports Restangular methods like put and post. The routing would be /documents/3

thinkingmedia avatar Sep 16 '16 22:09 thinkingmedia