问题
I am using Restangular. In my application, I have two REST resources,
To get the User based on the ID /users/123
To get the buddy details of the user users/123/buddies/456
Below is the code I am using,
//get the user
Restangular.one("users", 123).get().then(function(user){
$scope.user = user;
});
Restangular makes a call to /users/123. So far so good.
//get the buddy
var getBuddy = function(){
$scope.user.one("buddies", "456").get();
}
But here, Restangular makes the call to /users/buddies/456 instead of /users/123/buddies/456.
I have gone through the samples provided and I can't spot a mistake. Looks like I am overseeing the obvious but this issue has been frustrating me for more than a day now. Does anyone have a hint?
Thanks,
回答1:
try forming url like this.
Restangular.one("users", 123).one("buddies", 456).get().then(function(buddy){
$scope.buddy = buddy; });
or remove double quotes of "456" e.g one("buddies", 456), it should work.
回答2:
The answer lies in the Restangular documentation
If you are using MongoDB, remember to configure the id field.
来源:https://stackoverflow.com/questions/27855472/nested-resources-with-restangular