I understood that the concept of $resource in AngularJS is to return
- A resource, an object representing this resource (get, update, delete)
- A list of objects representing this resource (query)
I am using a backend which does not provide all needed information in one shot.
For example: /User/:id
user = User.get({id: userId}); returns a User. Great.
If I need to get the number of his friends, I have another request wich will be like:
/User/:id/count=friend
And return:
{ count: 17 }
Here I am stuck, I can't use my user variable, or I will lose my user object. Plus the result will be a number, which does not represent my user anymore.
The 'dirty' way would be to go back with $http for this and to assign the result to user.friendsNumber = data.count.
But still not clean, if I user.$put() something, I lose my user.friendsNumber as it will be reassigned.
What is the correct way to handle this properly?
$resource(url, [paramDefaults], [actions], options);