Skip to content Skip to sidebar Skip to footer

Ng-repeat Not Growing With Object

I'm doing this:
Find

    Solution 1:

    it works fine.

    http://plnkr.co/edit/agadSBFgz8YhWuDTtCPx?p=preview

    Your situation might be different.

    --------- EDIT ---------

    ok, I got your situation. You are running a function not under watch of AngularJS. Thus, AngularJS does not know that your variable is changed, basically $digest is not called.

    To mimic native Javascript asynchronous call, I use setTimeout.

    The following code does not work. It change the value, but it won't be watched.

    setTimeout( function() {
      $scope.presentations = [6,7,8,9];
    }, 1000);
    

    However this code does work. It change the value as expected

    $timeout( function() {
      $scope.presentations = [6,7,8,9];
    }, 1000);
    

    The difference between setTimeout and $timeout is that $timeout is running under watch of AngularJS. Thus to make it work, you need to run $scope.apply() after it, or within it as a function.

    This code does work with setTimeout.

    setTimeout( function() {
      $scope.presentations = [6,7,8,9];
      $scope.$apply();
    }, 1000);
    

    Can't explain all to you in detail because I don't really mastered the AngularJS code.

    This blog has a very good explanation about why we need to run $apply.

    http://jimhoskins.com/2012/12/17/angularjs-and-apply.html

    Just for the tip, to get the answer quickly, it's better to have a simplified example in jsfiddle or plunkr.
    I know $http call cannot be demoed in plunkr or jsfiddle, but you can mimic your situation using setTimeout. It can make your situation understandable to readers most of time.


Post a Comment for "Ng-repeat Not Growing With Object"