0
我需要运行一个查询来检索每个父级的子级列表。Restangular嵌套子查询无限循环
HTML:
<tr ng-repeat="parent in parents">
<td>{{parent.id}}</td>
<td>{{parent.name}}</td>
<td>
<li ng-repeat="child in getChildren(parent.id)">
{{child}}
</li>
</td>
</tr>
JS:
app.controller('mainCtrl', function($scope, Restangular) {
...
$scope.getChildren = function(parentId) {
console.log(parentId); //called over and over
//should GET e.g. /api/parents/1/children
return Restangular.one('parents', parentId).getList('children').then(function(children) {
console.log(JSON.stringify(children)); //never hit
return children;
})
}
我可以看到正确的API端点获取调用,但的getChildren()函数一再呼吁同parentId的。它似乎也永远不会回来。我确定它的一些明显的东西 - 我做错了什么?
似乎与此相关:Infinite loop with Angular expression binding但是,该示例不使用Restangular。