问题描述
堆栈跟踪:
Error: $apply already in progress
at Error (<anonymous>)
at beginPhase (file:///android_asset/www/built.min.js:7:22740)
at Object.Scope.$apply (file:///android_asset/www/built.min.js:7:25967)
at navigator.geolocation.getCurrentPosition.that (file:///android_asset/www/built.min.js:13:8670)
at Object.geolocation.getCurrentPosition (file:///android_asset/www/plugins/org.apache.cordova.core.geolocation/www/geolocation.js:122:13)
at Object.getCurrentPosition (file:///android_asset/www/built.min.js:13:8589)
at Object.getCurrentPosition (file:///android_asset/www/built.min.js:13:8277)
at Object.getCurrentCity (file:///android_asset/www/built.min.js:13:8941)
at Object.$scope.locateDevice (file:///android_asset/www/built.min.js:13:10480)
at file:///android_asset/www/built.min.js:7:12292:7
引用此代码http://pastebin.com/B9V6yvFu
getCurrentPosition: cordovaReady(function (onSuccess, onError, options) {
navigator.geolocation.getCurrentPosition(function () {
var that = this,
args = arguments;
if (onSuccess) {
$rootScope.$apply(function () {
onSuccess.apply(that, args);
});
}
}, function () {
var that = this,
args = arguments;
if (onError) {
$rootScope.$apply(function () {
onError.apply(that, args);
});
}
}, {
enableHighAccuracy: true,
timeout: 20000,
maximumAge: 18000000
});
})
奇怪的是,在我的 LG4X 上它运行良好,但是在我的 samsung s2 上它抛出了上述错误.有什么想法有什么问题吗?
Strange thing, on my LG4X it works fine, however on my samsung s2 it throws the above error. Any ideas whats wrong?
推荐答案
您收到此错误是因为您在现有消化循环内调用 $apply
.
You are getting this error because you are calling $apply
inside an existing digestion cycle.
最大的问题是:你为什么要调用 $apply
?除非您从非 Angular 事件接口,否则您永远不需要调用 $apply
.$apply
的存在通常意味着我做错了什么(除非再次发生 $apply 来自非 Angular 事件).
The big question is: why are you calling $apply
? You shouldn't ever need to call $apply
unless you are interfacing from a non-Angular event. The existence of $apply
usually means I am doing something wrong (unless, again, the $apply happens from a non-Angular event).
如果 $apply
在这里确实合适,请考虑使用安全应用"方法:
If $apply
really is appropriate here, consider using a "safe apply" approach:
https://coderwall.com/p/ngisma
这篇关于$apply 已经在进行中错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!