我有一个Ionic
应用程序,带有一个简单的角度控制器,一个服务和一个视图,它是一个项目列表。
当我使用POJO列表作为数据时,它可以正常工作。但是当我添加一个Parse查询find
时,会出现错误:
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以某种方式连接到Angular内部,但我无法弄清楚如何。
执行步骤:
/list
Angular JS代码:
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
解析SDK 1.6.14
我没有使用任何特定的Angular-Parse插件。
提前致谢!
PS:这是带有跟踪的错误堆栈:
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
答案 0 :(得分:0)
问题出在本节
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
)。因为每次摘要周期收到错误时都会在Angular $digest
上发生这种情况,$digest
会再次执行尝试收敛到正确状态,$digest
周期执行的次数仅限于10倍。这是错误日志中出现的内容,而不是Parse异常。
解决方案是在$ionicPlatform.ready
之前执行初始化:
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();
}
});
});