首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >当查询-错误:[$rootScope:infdig] 10 $digest()迭代达到时,解析JS与角JS冲突

当查询-错误:[$rootScope:infdig] 10 $digest()迭代达到时,解析JS与角JS冲突
EN

Stack Overflow用户
提问于 2016-01-25 05:09:30
回答 1查看 528关注 0票数 0

我有一个Ionic应用程序,有一个简单的角度控制器,一个服务和一个视图,这是一个项目列表。

当我使用POJO列表作为数据时,它可以正常工作。但是,当我添加一个解析查询find时,会出现以下错误:

代码语言:javascript
运行
复制
20    319061   error    Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: []
http://errors.angularjs.org/1.4.3/$rootScope/infdig?p0=10&p1=%5B%5D
minErr/<@http://localhost:8100/lib/ionic/js/ionic.bundle.js:13380:12
$RootScopeProvider/this.$get</Scope.prototype.$digest@http://localhost:8100/lib/ionic/js/ionic.bundle.js:29033:1
$RootScopeProvider/this.$get</Scope.prototype.$apply@http://localhost:8100/lib/ionic/js/ionic.bundle.js:29263:13
bootstrapApply@http://localhost:8100/lib/ionic/js/ionic.bundle.js:14945:9
invoke@http://localhost:8100/lib/ionic/js/ionic.bundle.js:17762:14
bootstrap/doBootstrap@http://localhost:8100/lib/ionic/js/ionic.bundle.js:14943:1
bootstrap@http://localhost:8100/lib/ionic/js/ionic.bundle.js:14963:1
angularInit@http://localhost:8100/lib/ionic/js/ionic.bundle.js:14857:5
@http://localhost:8100/lib/ionic/js/ionic.bundle.js:41671:5
trigger@http://localhost:8100/lib/ionic/js/ionic.bundle.js:16308:7
createEventHandler/eventHandler@http://localhost:8100/lib/ionic/js/ionic.bundle.js:16583:9

21    319062   error    Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: []
http://errors.angularjs.org/1.4.3/$rootScope/infdig?p0=10&p1=%5B%5D, http://localhost:8100/lib/ionic/js/ionic.bundle.js, Line: 13380

即使数据从未被使用过,也只是打了个电话。就像Parse在某种程度上连接到角度的内部,但我不知道如何。

执行步骤:

  1. 加载应用程序
  2. 路由器配置发送给/list
  3. 调用DataService.getBuildings()来解析控制器的参数
  4. 如果在getBuildings()中没有对Parse的调用,那么没有问题
  5. 如果有对Parse的调用,那么将再次调用该解析,直到出现递归错误。

角JS码:

代码语言:javascript
运行
复制
var app = angular.module('app', ['ionic'])
.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {

    if (window.cordova && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
      cordova.plugins.Keyboard.disableScroll(true);
    }
    if (window.StatusBar) {
      // Set the statusbar to use the default style, tweak this to
      // remove the status bar on iOS or change it to use white instead of dark colors.
      StatusBar.styleDefault();
    }

    Parse.initialize("KEY","VALUE"); // Parse credentials (with correct values in the real code)

  });
});

app.service('DataService', function($q) {
  return {
    buildingsI: [ // hardcoded data
      {
        id: 2,
        name: 'Colectivo',
    state_id: 1,
      },
      {
        id: 3,
        name: 'Otro',
    state_id: 1
      },
      {
        id: 4,
        name: 'Mas',
    state_id: 2
      }
    ]
    ,
    _getData: function() {

      console.log('_getData()');

      var defer = $q.defer();

      var BuildingObject = Parse.Object.extend("Building");
      Object.defineProperty(BuildingObject.prototype,"id",{
             get: function() {
            return this.get('id');
         },
         set: function(aval) {
            this.set('id',aval);
         }
      });
      Object.defineProperty(BuildingObject.prototype,"name",{
             get: function() {
            return this.get('name');
         },
         set: function(aval) {
            this.set('name',aval);
         }
      });

      var query = new Parse.Query(BuildingObject);
      query.include("state");
      query.limit(1000);
      query.ascending("name");
       console.log('Before find');
           query.find().then(function (data) {
                console.log(data);
                defer.resolve(data);
                             },
                             function (error) {
                defer.reject(error);
                             });
       console.log('After find');

       return defer.promise; 
    },

    getBuildings: function() {

        console.log('Call getBuildings(), begins getData');

        this._getData();// Here is the call that launchs Parse query, I don't use the data

        console.log('Ends getData');

        return this.buildingsI; // List of hardcoded data, the idea is to replace this with Parse data
    }
  }
});


app.controller('BuildingsCtrl', ['$scope','buildings',
   function($scope, buildingsP) {
       console.log('Call BuildingsCtrl constructor');
       console.log(buildingsP.length);
       this.buildings = buildingsP;
   }
]);



app.config(function($stateProvider, $urlRouterProvider) {
  $stateProvider
  .state('list', {
    url: '/list',
    cache: false,
    templateUrl: 'list.html',
    controller: 'BuildingsCtrl as myCtrl',
    resolve: {
      buildings: function($stateParams, DataService) {
        console.log('Call dataService');
        return DataService.getBuildings();
      }
    }
  });

  $urlRouterProvider.otherwise("/list");
});

如果我删除对_getData()的内部调用,应用程序就会呈现硬编码数据。如果我离开内部调用,它将到达对query.find(...)的调用,永远不会调用success函数,并开始从数据服务再次开始调用。稍后,它会抛出错误几次,但有一些不同之处(见下文)。

版本:

离子 1.2.4 Parse 1.6.14

我不使用任何特定的角-分析插件。

提前感谢!

PS:下面是带有跟踪的错误堆栈:

代码语言:javascript
运行
复制
ionic $ restart
Loading: /?restart=475324
ionic $ 0     531257   log      Call dataService
1     531258   log      Call getBuildings(), begins getData
2     531258   log      _getData()
3     531262   log      Before find
4     531275   log      Call dataService
5     531277   log      Call getBuildings(), begins getData
6     531279   log      _getData()
7     531279   log      Before find
8     531292   log      Call dataService
9     531292   log      Call getBuildings(), begins getData
10    531293   log      _getData()
11    531295   log      Before find
12    531344   log      Call dataService
13    531346   log      Call getBuildings(), begins getData
14    531347   log      _getData()
15    531348   log      Before find
16    531364   log      Call dataService
17    531366   log      Call getBuildings(), begins getData
18    531369   log      _getData()
19    531371   log      Before find
20    531376   error    Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: []
http://errors.angularjs.org/1.4.3/$rootScope/infdig?p0=10&p1=%5B%5D
minErr/<@http://localhost:8100/lib/ionic/js/ionic.bundle.js:13380:12
$RootScopeProvider/this.$get</Scope.prototype.$digest@http://localhost:8100/lib/ionic/js/ionic.bundle.js:29033:1
$RootScopeProvider/this.$get</Scope.prototype.$apply@http://localhost:8100/lib/ionic/js/ionic.bundle.js:29263:13
bootstrapApply@http://localhost:8100/lib/ionic/js/ionic.bundle.js:14945:9
invoke@http://localhost:8100/lib/ionic/js/ionic.bundle.js:17762:14
bootstrap/doBootstrap@http://localhost:8100/lib/ionic/js/ionic.bundle.js:14943:1
bootstrap@http://localhost:8100/lib/ionic/js/ionic.bundle.js:14963:1
angularInit@http://localhost:8100/lib/ionic/js/ionic.bundle.js:14857:5
@http://localhost:8100/lib/ionic/js/ionic.bundle.js:41671:5
trigger@http://localhost:8100/lib/ionic/js/ionic.bundle.js:16308:7
createEventHandler/eventHandler@http://localhost:8100/lib/ionic/js/ionic.bundle.js:16583:9

21    531379   error    Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: []
http://errors.angularjs.org/1.4.3/$rootScope/infdig?p0=10&p1=%5B%5D, http://localhost:8100/lib/ionic/js/ionic.bundle.js, Line: 13380
22    531481   log      Call dataService
23    531497   log      Call getBuildings(), begins getData
24    531498   log      _getData()
25    531500   log      Before find
26    531505   log      After find
27    531506   log      Ends getData
28    531529   log      Call BuildingsCtrl constructor
29    531530   log      11
30    531727   error    too much recursion, http://localhost:8100/js/parse-1.6.14.js, Line: 3319
0     532183   log      Call dataService
1     532183   log      Call getBuildings(), begins getData
2     532184   log      _getData()
3     532186   log      Before find
4     532195   log      Call dataService
6     532198   log      _getData()
5     532197   log      Call getBuildings(), begins getData
7     532199   log      Before find
8     532206   log      Call dataService
9     532236   log      Call getBuildings(), begins getData
10    532237   log      _getData()
11    532238   log      Before find
12    532254   log      Call dataService
13    532256   log      Call getBuildings(), begins getData
14    532258   log      _getData()
15    532261   log      Before find
16    532269   log      Call dataService
17    532271   log      Call getBuildings(), begins getData
20    532275   error    Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: []
http://errors.angularjs.org/1.4.3/$rootScope/infdig?p0=10&p1=%5B%5D
minErr/<@http://localhost:8100/lib/ionic/js/ionic.bundle.js:13380:12
$RootScopeProvider/this.$get</Scope.prototype.$digest@http://localhost:8100/lib/ionic/js/ionic.bundle.js:29033:1
$RootScopeProvider/this.$get</Scope.prototype.$apply@http://localhost:8100/lib/ionic/js/ionic.bundle.js:29263:13
bootstrapApply@http://localhost:8100/lib/ionic/js/ionic.bundle.js:14945:9
invoke@http://localhost:8100/lib/ionic/js/ionic.bundle.js:17762:14
bootstrap/doBootstrap@http://localhost:8100/lib/ionic/js/ionic.bundle.js:14943:1
bootstrap@http://localhost:8100/lib/ionic/js/ionic.bundle.js:14963:1
angularInit@http://localhost:8100/lib/ionic/js/ionic.bundle.js:14857:5
@http://localhost:8100/lib/ionic/js/ionic.bundle.js:41671:5
trigger@http://localhost:8100/lib/ionic/js/ionic.bundle.js:16308:7
createEventHandler/eventHandler@http://localhost:8100/lib/ionic/js/ionic.bundle.js:16583:9

18    532272   log      _getData()
19    532273   log      Before find
21    532276   error    Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: []
http://errors.angularjs.org/1.4.3/$rootScope/infdig?p0=10&p1=%5B%5D, http://localhost:8100/lib/ionic/js/ionic.bundle.js, Line: 13380
22    532318   log      Call dataService
23    532320   log      Call getBuildings(), begins getData
24    532322   log      _getData()
25    532325   log      Before find
26    532332   log      After find
27    532334   log      Ends getData
28    532357   log      Call BuildingsCtrl constructor
29    532360   log      11
0     532570   log      Call dataService
1     532571   log      Call getBuildings(), begins getData
2     532573   log      _getData()
3     532577   log      Before find
4     532640   log      Call dataService
5     532641   log      Call getBuildings(), begins getData
6     532643   log      _getData()
7     532644   log      Before find
8     532716   log      Call dataService
9     532717   log      Call getBuildings(), begins getData
10    532718   log      _getData()
11    532719   log      Before find
12    532728   log      Call dataService
14    532729   log      _getData()
13    532728   log      Call getBuildings(), begins getData
16    532738   log      Call dataService
15    532730   log      Before find
18    532740   log      _getData()
17    532739   log      Call getBuildings(), begins getData
19    532741   log      Before find
20    532746   error    Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: []
http://errors.angularjs.org/1.4.3/$rootScope/infdig?p0=10&p1=%5B%5D
minErr/<@http://localhost:8100/lib/ionic/js/ionic.bundle.js:13380:12
$RootScopeProvider/this.$get</Scope.prototype.$digest@http://localhost:8100/lib/ionic/js/ionic.bundle.js:29033:1
$RootScopeProvider/this.$get</Scope.prototype.$apply@http://localhost:8100/lib/ionic/js/ionic.bundle.js:29263:13
bootstrapApply@http://localhost:8100/lib/ionic/js/ionic.bundle.js:14945:9
invoke@http://localhost:8100/lib/ionic/js/ionic.bundle.js:17762:14
bootstrap/doBootstrap@http://localhost:8100/lib/ionic/js/ionic.bundle.js:14943:1
bootstrap@http://localhost:8100/lib/ionic/js/ionic.bundle.js:14963:1
angularInit@http://localhost:8100/lib/ionic/js/ionic.bundle.js:14857:5
@http://localhost:8100/lib/ionic/js/ionic.bundle.js:41671:5
trigger@http://localhost:8100/lib/ionic/js/ionic.bundle.js:16308:7
createEventHandler/eventHandler@http://localhost:8100/lib/ionic/js/ionic.bundle.js:16583:9

21    532747   error    Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: []
http://errors.angularjs.org/1.4.3/$rootScope/infdig?p0=10&p1=%5B%5D, http://localhost:8100/lib/ionic/js/ionic.bundle.js, Line: 13380
30    532775   error    too much recursion, http://localhost:8100/js/parse-1.6.14.js, Line: 3319
22    532786   log      Call dataService
23    532786   log      Call getBuildings(), begins getData
24    532787   log      _getData()
25    532788   log      Before find
26    532798   log      After find
27    532799   log      Ends getData
28    532817   log      Call BuildingsCtrl constructor
29    532818   log      11
0     533004   log      Call dataService
1     533005   log      Call getBuildings(), begins getData
2     533006   log      _getData()
3     533008   log      Before find
4     533017   log      Call dataService
6     533018   log      _getData()
5     533018   log      Call getBuildings(), begins getData
7     533019   log      Before find
8     533028   log      Call dataService
9     533033   log      Call getBuildings(), begins getData
10    533034   log      _getData()
11    533036   log      Before find
12    533046   log      Call dataService
13    533048   log      Call getBuildings(), begins getData
14    533048   log      _getData()
15    533050   log      Before find
16    533060   log      Call dataService
17    533069   log      Call getBuildings(), begins getData
20    533074   error    Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: []
http://errors.angularjs.org/1.4.3/$rootScope/infdig?p0=10&p1=%5B%5D
minErr/<@http://localhost:8100/lib/ionic/js/ionic.bundle.js:13380:12
$RootScopeProvider/this.$get</Scope.prototype.$digest@http://localhost:8100/lib/ionic/js/ionic.bundle.js:29033:1
$RootScopeProvider/this.$get</Scope.prototype.$apply@http://localhost:8100/lib/ionic/js/ionic.bundle.js:29263:13
bootstrapApply@http://localhost:8100/lib/ionic/js/ionic.bundle.js:14945:9
invoke@http://localhost:8100/lib/ionic/js/ionic.bundle.js:17762:14
bootstrap/doBootstrap@http://localhost:8100/lib/ionic/js/ionic.bundle.js:14943:1
bootstrap@http://localhost:8100/lib/ionic/js/ionic.bundle.js:14963:1
angularInit@http://localhost:8100/lib/ionic/js/ionic.bundle.js:14857:5
@http://localhost:8100/lib/ionic/js/ionic.bundle.js:41671:5
trigger@http://localhost:8100/lib/ionic/js/ionic.bundle.js:16308:7
createEventHandler/eventHandler@http://localhost:8100/lib/ionic/js/ionic.bundle.js:16583:9

21    533075   error    Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: []
http://errors.angularjs.org/1.4.3/$rootScope/infdig?p0=10&p1=%5B%5D, http://localhost:8100/lib/ionic/js/ionic.bundle.js, Line: 13380
18    533069   log      _getData()
19    533070   log      Before find
22    533153   log      Call dataService
23    533155   log      Call getBuildings(), begins getData
24    533155   log      _getData()
25    533156   log      Before find
27    533163   log      Ends getData
26    533162   log      After find
28    533179   log      Call BuildingsCtrl constructor
29    533180   log      11
30    533220   error    too much recursion, http://localhost:8100/js/parse-1.6.14.js, Line: 3319
30    533391   error    too much recursion, http://localhost:8100/js/parse-1.6.14.js, Line: 3319
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-01-28 14:10:01

问题在本节。

代码语言:javascript
运行
复制
var app = angular.module('app', ['ionic'])
.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {

    if (window.cordova && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
      cordova.plugins.Keyboard.disableScroll(true);
    }
    if (window.StatusBar) {
      // Set the statusbar to use the default style, tweak this to
      // remove the status bar on iOS or change it to use white instead of dark colors.
      StatusBar.styleDefault();
    }

    Parse.initialize("KEY","VALUE"); // Parse credentials (with correct values in the real code)

  });
});

在呈现视图之后执行调用$ionicPlatform.ready,并且Parse的初始化在其中。

因此,当视图呈现被调用时,DataService.getBuildings()被调用,里面是query.find(),它抛出一个Parse异常,因为它没有初始化($ionicPlatform.ready在后面执行)。因为每次摘要周期收到错误时,都会在角$digest上发生这种情况,因此将再次执行$digest,试图收敛到正确的状态,而执行$digest循环的次数限制在10次。这就是出现在错误日志上的内容,而不是Parse异常。

解决方案是在$ionicPlatform.ready之前执行初始化:

代码语言:javascript
运行
复制
var app = angular.module('app', ['ionic'])
.run(function($ionicPlatform) {

  Parse.initialize("KEY","VALUE");// MOVED OUT OF 'ready'

  $ionicPlatform.ready(function() {

    if (window.cordova && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
      cordova.plugins.Keyboard.disableScroll(true);
    }
    if (window.StatusBar) {
      // Set the statusbar to use the default style, tweak this to
      // remove the status bar on iOS or change it to use white instead of dark colors.
      StatusBar.styleDefault();
    }
  });
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34985527

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档