奇怪的Angular异常:[$ rootScope:inprog] null已在进行中 [英] Weird Angular exception: [$rootScope:inprog] null already in progress

查看:111
本文介绍了奇怪的Angular异常:[$ rootScope:inprog] null已在进行中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在AngularJS 1.5.9中遇到了一个非常奇怪的异常

I get a very strange exception with AngularJS 1.5.9

[$ rootScope:inprog] null已在进行中

[$rootScope:inprog] null already in progress

以下是引发此异常的源代码:

Here is the source code where this exception is thrown:

function beginPhase(phase) {
  if ($rootScope.$$phase) {
    throw $rootScopeMinErr('inprog', '{0} already in progress', $rootScope.$$phase);
  }

  $rootScope.$$phase = phase;
}

beginPhase()用"$ apply"或"$ digest"调用.

beginPhase() is called with "$apply" or "$digest".

我的问题是:

  • $ rootScope.$$ phase 为空的情况下如何输入"if"?
  • How is it possible to enter the "if" while $rootScope.$$phase is null?

任何帮助将不胜感激.

推荐答案

要回答您的问题 $ rootScope.$$ phase 可以设置为 空" (字符串),将导致引发此错误.

To answer your question $rootScope.$$phase can be set to "null" (string) which will result in this error being thrown.

我不确定您如何捕获此消息,但Sentry报告说,对我来说,我只是从一堆用户那里收到大量此类异常.

I'm not sure how you were able to capture this message but Sentry reports that for me and I'm getting a ton of those exceptions from just a bunch of users.

因此,为了减少垃圾邮件,我做了一个函数,该函数将从例外,并将清除 $ rootScope.$$ phase ,这有望防止再次发生:

So in order to reduce the spam I made a function which will remove the stack from the exception, and will clear the $rootScope.$$phase which will hopefully prevent a second occurrence:

function exceptionHandler(){
    const error = Error;
    const nullMessage = "[$rootScope:inprog] null already in progress";

    function exception(message){
        if(message.indexOf(nullMessage) === 0){
            const $rootScope = exceptionHandler.$rootScope;
            if($rootScope) $rootScope.$$phase = null;

            const exception = new error(nullMessage);
            exception.stack = "";
            return exception;
        }

        return new error(message);
    }

    Error = exception;
}

exceptionHandler(); // If it's not run AngularJS will use the original Error constructor, the one we're decorating

然后在 angular.run 中注入 $ rootScope 并将其设置为函数的属性:

And then in angular.run inject $rootScope and set it as a property of the function:

angular.run(["$rootScope", function($rootScope){
    exceptionHandler.$rootScope = $rootScope;
}]);

我的假设是扩展将 $ rootScope.$$ phase 设置为"null" ,但是在安装了与我的一个用户相同的扩展后,没有例外发生.

My assumption was that an extension was setting $rootScope.$$phase to "null" but after installing the same extensions as one of my users the exception did not occur.

在GistHub上加星标

这篇关于奇怪的Angular异常:[$ rootScope:inprog] null已在进行中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆