angularjs – $apply already in progress错误

前端之家收集整理的这篇文章主要介绍了angularjs – $apply already in progress错误前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
堆栈跟踪:
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,{
            enableHighAccuracy: true,timeout: 20000,maximumAge: 18000000
        });
    })

奇怪的是,在我的LG4X它工作正常,但是在我的三星s2它抛出以上错误。任何想法有什么问题?

你得到这个错误,因为你在现有的消化循环中调用$ apply。

最大的问题是:你为什么叫$ apply?你不应该需要调用$ apply,除非你是从非角事件接口。 $ apply的存在通常意味着我做错了(除非,$ apply发生在非Angular事件)。

如果$ apply真的适合这里,考虑使用“安全应用”方法

https://coderwall.com/p/ngisma

原文链接:https://www.f2er.com/angularjs/147099.html

猜你在找的Angularjs相关文章