I need to run a query to retrieve a list of children from each parent.
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;
})
}
I can see the correct API endpoint is getting called, but the getChildren() function is called repeatedly for the same parentId. It also never seems to return. I'm sure its something obvious - what am I doing wrong?
Seems related to this: Infinite loop with Angular expression binding however that example doesnt use Restangular.