cgross / angular-busy

Show busy/loading indicators on any element during $http requests (or any promise).
http://cgross.github.io/angular-busy/demo
MIT License
1.44k stars 256 forks source link

Uncaught Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting! #77

Open mukulgupta2507 opened 9 years ago

mukulgupta2507 commented 9 years ago

Hi,

I have recently integrated angular-busy in my project. As soon as I integrated in my project, it started giving me following error:

Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: [[{"msg":"fn: regularInterceptedExpression","newVal":64,"oldVal":63}],[{"msg":"fn: regularInterceptedExpression","newVal":65,"oldVal":64}],[{"msg":"fn: regularInterceptedExpression","newVal":66,"oldVal":65}],[{"msg":"fn: regularInterceptedExpression","newVal":67,"oldVal":66}],[{"msg":"fn: regularInterceptedExpression","newVal":68,"oldVal":67}]]
http://errors.angularjs.org/1.4.5/$rootScope/infdig?p0=10&p1=%5B%5B%7B%22ms…rInterceptedExpression%22%2C%22newVal%22%3A68%2C%22oldVal%22%3A67%7D%5D%5D
    at REGEX_STRING_REGEXP (angular.js:68)
    at Scope.$get.Scope.$digest (angular.js:15753)
    at Scope.$get.Scope.$apply (angular.js:15986)
    at angular.js:17753
    at completeOutstandingRequest (angular.js:5490)
    at angular.js:5762(anonymous function) @ angular.js:12416$get @ angular.js:9203$get.Scope.$apply @ angular.js:15988(anonymous function) @ angular.js:17753completeOutstandingRequest @ angular.js:5490(anonymous function) @ angular.js:5762
angular.js:68 Uncaught Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: [[{"msg":"fn: regularInterceptedExpression","newVal":64,"oldVal":63}],[{"msg":"fn: regularInterceptedExpression","newVal":65,"oldVal":64}],[{"msg":"fn: regularInterceptedExpression","newVal":66,"oldVal":65}],[{"msg":"fn: regularInterceptedExpression","newVal":67,"oldVal":66}],[{"msg":"fn: regularInterceptedExpression","newVal":68,"oldVal":67}]]
http://errors.angularjs.org/1.4.5/$rootScope/infdig?p0=10&p1=%5B%5B%7B%22ms…rInterceptedExpression%22%2C%22newVal%22%3A68%2C%22oldVal%22%3A67%7D%5D%5D

I have searched on internet and it seems to be some angularjs issue which comes when there is some function which returns an array of objects.

I'm using two promises as used in this plunker http://plnkr.co/edit/VO7K2eE7GmEp0UY9wmbi?p=preview mentioned in this thread https://github.com/cgross/angular-busy/issues/29.

Here is my code of promises:

    $scope.removeUploadedFile = function(files, idx) {
      // files.splice(idx, 1);
      // console.log($scope.uploadedFiles);
      // $scope.uploadedFiles = files;
      // console.log($scope.uploadedFiles);
      var fileId = files[idx]['result']['data']['filePublicId'];
      console.log("remove file");
      $scope.removeFilePromise = Auth.deleteFile(fileId)   // First promise
      .then(function(data){
        console.log("index");
        console.log(idx);
        files.splice(idx, 1);
        console.log($scope.uploadedFiles);
        $scope.uploadedFiles = files;
        console.log($scope.uploadedFiles);        
      })
      .catch(function(err){
        ToasterService.notify('error', "Error!", "Please try again!!");
      });

    }

    $scope.upload = function(files) {
        $scope.uploadedFiles = files;
        angular.forEach(files, function(file) {
            if (file && !file.$error) {
                // if($scope.uploadedFiles.indexOf(file) == -1) {
                //   $scope.uploadedFiles.push(file);
                // }
                file.showremoveButton = false;
                file.upload = Upload.upload({
                  url: 'uploader',
                  file: file,
                  userId: $scope.user._id
                });
                file.upload.then(function (response) {
                  $timeout(function () {
                    file.result = response;
                    file.showremoveButton = true;
                  });
                }, function (response) {
                  console.log(response);
                  if (response.status == 500) {
                    var idx = $scope.uploadedFiles.indexOf(file);
                    $scope.uploadedFiles.splice(idx, 1);
                    console.log($scope.uploadedFiles);
                  }
                });
                $scope.fileUploadPromise = file.upload;  // Second promise
                file.upload.progress(function (evt) {
                  file.progress = Math.min(100, parseInt(100.0 * evt.loaded / evt.total));
                  console.log("file progress");
                  console.log(file.progress);
                });
          }   
        });
        console.log(JSON.stringify($scope.uploadedFiles));
        console.log(JSON.stringify(files));

    }

    <div class="loader" cg-busy="{ promise: [ removeFilePromise, fileUploadPromise ], message:message }">&nbsp;</div>

Can anyone please help me where exactly am I doing wrong ?

Thanks

JosephDAM commented 9 years ago

Same problem, but #29 says that cg-busy="{ promise: [ removeFilePromise, fileUploadPromise ] }" does NOT work. My problem is that $scope.promises = [$scope.promise1, $scope.promise2] + cg-busy="{ promise: promises }" does not start the cgBusy...

schermannj commented 8 years ago

+