0

I have an array, whose only value is current "1". It conferences a unique id in my MySQL database that I query through HTTP get to grab information on, I'm 100% sure my get request is not failing.

Here's the HTML code:

<dl>
<dt ng-repeat="x in favorites">{{getName(x)}}</dt>
<dd ng-repeat-end></dd>
</dl>

This is inside my controller and uses this code:

$scope.getName = function(x) {
    console.log(x);
    $http.get(GetURL + x)
        .success(function(x) {
            return x.name;
        })
        .error(function() {
            console.log("Abort Abort!!!");
            exit();
        })
}   

But whenever I run this, it pulls uncaught error "infinite digest loop". I can't see why this code is causing an infinite digest loop though, it definitely has something to do with my getName function, because once I removed it, the infinite digest loop stopped, but I can't seem to figure out why

q.Then
  • 2,743
  • 1
  • 21
  • 31
  • That is because you are invoking an `$http` in a watched expression - DON'T do that! And in general, watched expressions should be extremely fast - basically just getters - because they run on every digest cycle – New Dev Feb 20 '15 at 04:06
  • Also, what you are trying to do here will not work. Expressions don't support promises, so you can't return a promise and then resolve it with `x.name` as the return value. Get the names first and store it in `favorites` - then `ng-repeat` over them. And try to have a single $http request that gets all the names, instead of request-per-name – New Dev Feb 20 '15 at 04:10

0 Answers0