I am trying to get some data from a REST api using mgonto's Restangular.
// Restangular returns promises
Restangular.all('users').getList() // GET: /users
.then(function(users) {
// returns a list of users
$scope.user = users[0]; // first Restangular obj in list: { id: 123 }
})
// Later in the code...
// Restangular objects are self-aware and know how to make their own RESTful requests
$scope.user.getList('cars'); // GET: /users/123/cars
That's fine, and this works, but all the results returned in the promises callbacks have some methods and properties added by Restangular (this is how you can do .getList("cars") on a user).
What I want is to retrieve only the user's data (name, id...) without all the Restangular methods. Just a plain JS object.
I couldn't find any way to do this in the docs. Everytime I use a method on a returned user it always returns a wrapped object with the Restangular methods.
I am trying to get some data from a REST api using mgonto's Restangular.
// Restangular returns promises
Restangular.all('users').getList() // GET: /users
.then(function(users) {
// returns a list of users
$scope.user = users[0]; // first Restangular obj in list: { id: 123 }
})
// Later in the code...
// Restangular objects are self-aware and know how to make their own RESTful requests
$scope.user.getList('cars'); // GET: /users/123/cars
That's fine, and this works, but all the results returned in the promises callbacks have some methods and properties added by Restangular (this is how you can do .getList("cars") on a user).
What I want is to retrieve only the user's data (name, id...) without all the Restangular methods. Just a plain JS object.
I couldn't find any way to do this in the docs. Everytime I use a method on a returned user it always returns a wrapped object with the Restangular methods.
Share asked Aug 27, 2015 at 15:49 RayjaxRayjax 7,78413 gold badges57 silver badges85 bronze badges1 Answer
Reset to default 8I guess you are looking for 'plain()' (alias for Restangular.stripRestangular(elem)).
plain(): Returns the plain element received from the server without any of the enhanced methods from Restangular. It's an alias to calling Restangular.stripRestangular(elem)
It strips all the restangular methods and returns the plain object which is returned by the server.
For more information please refer to the following link :
https://github./mgonto/restangular#element-methods
The following fiddle might help :
Fiddle ::
http://plnkr.co/edit/oMFnYM4HkaFK3biscpTo?p=preview
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742294013a4416747.html
评论列表(0条)