角度ng-repeat dosen等待范围

时间:2015-10-22 17:53:29

标签: javascript angularjs scope angularjs-scope angularjs-ng-repeat

HTML

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

脚本

    .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);
    })
});

时间表从一个休息api加载,但它接缝像ng-repeat dosen等待范围。

如果我将时间表设置为某个值,则重复运行它。

那么如何告诉ng-repeat等待范围被加载?

1 个答案:

答案 0 :(得分:0)

我猜测dpd.timesheetold.get是异步调用,并且它不会触发$digest周期 - 因此您的视图永远不会更新。您可以使用$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);
    })
});
相关问题