错误:[$ rootScope:inprog] $ digest已在进行中 - PromiseObjecs / For循环

时间:2015-09-04 10:10:09

标签: javascript angularjs

Error: [$rootScope:inprog] $digest already in progress

基本上我试图在for循环中同时运行两个promise对象:

angular.module('core').controller('HomeController', function($q, $http, $scope) {

for (var i = 0; i < window.config.Environments.length; i++) {
    for (var j = 1; j < window.config.Clusters[i] + 1; j++) {

//Promise Object 1
        promiseObj.physical[window.config.Environments[i] + "#Cluster" + j] = $http.get('url/search?idc=' + window.config.Environments[i] + '&type=Physical&cluster=' + j).success(function(i,j) {
            return function(data) {

            $scope.servers = data; // get data from json

            angular.forEach($scope.servers, function(item) {

                //some code
            });
            }

        }(i,j));
    //Promise Object 1
           promiseObj.virtual[window.config.Environments[i] + "#Cluster" + j] = $http.get('url/search?idc=' + window.config.Environments[i] + '&type=Virtual&cluster=' + j).success(function(i,j) {
            return function(data) {

            angular.forEach($scope.virtualservers, function(item) {
  //some code


            });

            }

        }(i,j));

}
}
});
  • 为什么会出现这种错误(为我的无知道歉,但我不明白我在哪里叫$ digest)

提前谢谢

0 个答案:

没有答案