错误:精华已在进行中 [英] Error: Digest already in Progress

查看:207
本文介绍了错误:精华已在进行中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下错误:


  

错误:[$ rootScope:inprog] $消化正在进行中
   http://errors.angularjs.org/1.2.16/ $ rootScope / inprog?P0 =%24digest


不太清楚这个问题的根源是或究竟意味着还是什么阶段应用或消化是什么意思?我读了网页和理解适用/摘要上调用对象的范围和

  element.on(鼠标松开,函数(){
 范围。$应用(函数(){
 $ scope.doStuff();
 });
});

变成了:

  $ =应用功能(FN){
尝试{
  FN();
}最后(){
  $消化();
}
}


解决方案

如果你调用这可能会出现 $ scope.apply ,而消化函数被调用。意义和最有可能您scope.apply不是必需的。


  

从角文档 $消化()处理所有目前的范围及其子女的观察家。通常情况下,你不叫$ 消化()在控制器或指令直接。


  
  

角跟踪我们是在什么阶段的处理,与此相关的是$应用和$消化。试图重新输入一个$摘要或$应用而他们中的一个已经在进行中通常是需要修复编程错误的标志。因此,当发生角将抛出此错误。 点击这里了解更多详情


您code提醒,需要在早期版本的角度(0.4或0.8)中实现,但只要回想它不是在角的版本,您使用的是需要一个老把戏。

另外请注意,角团队为我们提供了一种诊断这种类型的错误

当您收到此错误它可以是相当艰巨的诊断问题的原因。行动,最好的办法是调查从错误的堆栈跟踪。你需要找地方$应用或$消化已经打来电话,找到发生此情况的背景。

有应该有两个呼叫:

首先调用的是良好的应用$ / $消化,通常由附近的调用堆栈的顶部一些事件触发。

第二个电话是坏的申请$ / $消化,这是一个调查。

一旦你确定了这个电话,你以你的方式堆栈,看看是什么问题。

如果第二个电话是在您的应用程序code做,那么你应该看看为什么这code已经从内$称为应用/ $摘要。它可能是一个简单的疏忽或者它与前面所述的同步/异步的情况相符。

如果第二个电话是一个角指令中所做的,那么很可能它前面描述的第二个纲领性事件触发的情况相匹配。在这种情况下,你可能需要进一步查找树是什么引发摆在首位的事件。

I have the following error:

Error: [$rootScope:inprog] $digest already in progress http://errors.angularjs.org/1.2.16/$rootScope/inprog?p0=%24digest

Not quite sure what the root of this problem is or what exactly this means or what the phases "apply" or "digest" mean? I read the page and understand that apply/digest is called on a scope objects and

element.on('mouseup', function() {
 scope.$apply(function() {
 $scope.doStuff();
 });
});

becomes:

$apply = function(fn) {
try {
  fn();
} finally() {
  $digest();
}
}

解决方案

This may occur if you call $scope.apply while the digest function is being called. Meaning and most likely your scope.apply is not required.

From Angular Docs: $digest() Processes all of the watchers of the current scope and its children. Usually, you don't call $digest() directly in controllers or in directives.

Angular keeps track of what phase of processing we are in, the relevant ones being $apply and $digest. Trying to reenter a $digest or $apply while one of them is already in progress is typically a sign of programming error that needs to be fixed. So Angular will throw this error when that occurs. Click Here for more details

Your code reminds an old trick that needed to be implemented in earlier versions of angular(0.4 or 0.8) but as far as recall it is not required in the version of angular that you are using.

Also note that Angular Team offered us a way to diagnose this type of errors:

When you get this error it can be rather daunting to diagnose the cause of the issue. The best course of action is to investigate the stack trace from the error. You need to look for places where $apply or $digest have been called and find the context in which this occurred.

There should be two calls:

The first call is the good $apply/$digest and would normally be triggered by some event near the top of the call stack.

The second call is the bad $apply/$digest and this is the one to investigate.

Once you have identified this call you work your way up the stack to see what the problem is.

If the second call was made in your application code then you should look at why this code has been called from within a $apply/$digest. It may be a simple oversight or maybe it fits with the sync/async scenario described earlier.

If the second call was made inside an Angular directive then it is likely that it matches the second programmatic event trigger scenario described earlier. In this case you may need to look further up the tree to what triggered the event in the first place.

这篇关于错误:精华已在进行中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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