Nested resources with Restangular

好久不见. 提交于 2019-12-24 13:37:23

问题


I am using Restangular. In my application, I have two REST resources,

  1. To get the User based on the ID /users/123

  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!