2

html

 <div ng-repeat="item in timesheets">{{item.week}}</div>

script

    .controller('TimesheetMainCtrl', function ($rootScope, $scope, $window) {

    dpd.timesheetold.get(function (result, err) {

        if (err) return console.log(err);
        $scope.timesheets = result;
        console.log($scope.timesheets);
    })
});

timesheets loads from a rest api, but it seams like ng-repeat dosen't wait for the scope.

if i set timesheets to a value, ng repeat runs it.

so how do i tell ng-repeat to wait for scope to be loaded ?

Thomas
  • 123
  • 1
  • 1
  • 12
  • does `dpd.timesheetold.get` has implemented with `$http`/`$resource`/`$q` or is that ajax going from other plugin? – Pankaj Parkar Oct 22 '15 at 17:55
  • 1
    what does `result` look like and where is the service code for `timesheetold.get`. Not enough information given – charlietfl Oct 22 '15 at 17:59
  • dpd is a rest script generatet by deployd – Thomas Oct 22 '15 at 18:09
  • ok... then that is outside of angular core and solution provided below should work. Anything that changes scope outside of angulaar has to notify angular to run digest – charlietfl Oct 22 '15 at 18:12

1 Answers1

0

I'm guessing that dpd.timesheetold.get is an async call and it doesn't trigger a $digest cycle - so your view never updates. You can manually trigger one with $timeout

.controller('TimesheetMainCtrl', function ($rootScope, $scope, $window, $timeout) {

    dpd.timesheetold.get(function (result, err) {

        if (err) return console.log(err);
        $timeout(function() {
            $scope.timesheets = result;
        });
        //console.log($scope.timesheets);
    })
});
tymeJV
  • 103,943
  • 14
  • 161
  • 157
  • nice, this worked then i just have to manually trigger with timeout each time i use dpd ? – Thomas Oct 22 '15 at 18:12
  • @ThomasBlauenfeldt -- Yeah.. anytime you use a 3rd party module that isn't injected - chances are it won't trigger a `$digest` cycle - so you'll need to take care of that. – tymeJV Oct 22 '15 at 18:16