Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs Restangular-如何使用GET方法访问此API?_Angularjs_Restangular - Fatal编程技术网

Angularjs Restangular-如何使用GET方法访问此API?

Angularjs Restangular-如何使用GET方法访问此API?,angularjs,restangular,Angularjs,Restangular,如何使用以下签名对REST API进行GET调用: http://www.example.com/hierarchies/nodes/1005/parents 我尝试这样调用API: var service = Restangular.all('hierarchies'); return service.one('nodes', id).all('parents').get(); 但它会抛出以下错误: TypeError: Cannot read property 'toString' o

如何使用以下签名对REST API进行GET调用:

http://www.example.com/hierarchies/nodes/1005/parents
我尝试这样调用API:

var service = Restangular.all('hierarchies');

return service.one('nodes', id).all('parents').get();
但它会抛出以下错误:

TypeError: Cannot read property 'toString' of undefined
API调用(如果成功)将以嵌套格式响应,如下所示:

{
    name: "",
    children: [
        {
            name: "",
            children: [
                {
                    name: "",
                    children: [
                        ..
                    ]
                }
            ]
        }
    ]
}

提前谢谢

我认为如果您使用
all
作为构建器的最后一部分,则需要一个列表,您应该使用
getList
而不是
get
。但是,您期望的对象看起来不像列表,因此您可以将生成器的最后一部分更改为仅使用
one
,而不使用第二个参数,然后使用单个对象作为响应

service.one('nodes', 5).one('parents').get().then(function(response) {
});