У меня есть приложение Ionic
с простым угловым контроллером, службой и представлением, которое представляет собой список элементов.
Когда я использую список POJO в качестве данных, он работает нормально. Но когда я добавить Анализировать запрос find
там happends ошибки:
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 каким-то образом связано с угловыми внутренностями, но я не могу понять, как это сделать.
Шаги выполнения:
/list
Угловой код 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()
приложение _getData()
жестко заданные данные. Если я оставил внутренний вызов, он достигает вызова функции query.find(...)
, никогда не вызывает функцию success
и начинает снова запускать вызов из службы данных. Позже он выдает ошибку несколько раз, с некоторыми отличиями (см. Ниже).
Версии:
Ионный 1.2.4
Parse 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
Проблема в этом разделе
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()
, внутри которого is query.find()
который 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();
}
});
});
"state"
которое вы включаете, есть"buildings"
? Попробуйте удалитьquery.include("state")
и посмотреть, все равно ли он выдает ошибки рекурсии. Кстати, это не просто ошибки углового броска, есть многоtoo much recursion
ошибокtoo much recursion
от разбора, который, кажется, указывает, что здания находят состояния, который находит больше зданий, который находит больше состояний, на неопределенный срок.