AngularJS $消化正在进行中 [英] AngularJS $digest already in progress

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

问题描述

我,当我将数据加载到角前pression得到一个错误。数据得到加载,但我得到的错误$消化正在进行中。

I'm getting an error when I'm loading data into an angular expression. The data get loaded, but I get the error $digest already in progress.

var dom = angular.element($compile(template)($scope));
$scope.$apply();
var html = $('<div>').append(dom).html();

我在这里给你我的模板的一小部分:

I'll give you a small part of my template here:

<b>Name: </b>{{model.project.description}}<br />
<b>Littera: </b>{{model.littera}}<br />
<b>Address: </b>{{model.address}}<br />

现在我都试过包裹$范围。$适用()到if语句像下面。但我听说是一个糟糕的方​​式做到这一点。不要紧那么多我猜,因为它没有反正工作。

Now I have tried wrapping the $scope.$apply() into an if statement like below. But I've heard that is a bad way to do it. Doesn't matter that much I guess since it didn't work anyway.

if (scope.$$phase) {
     scope.$apply();
}

据删除这些错误,但现在的数据绑定不工作。现在输出的是前pressions,而不是实际的数据。
我也试图把$范围。$适用()到$超时功能,但同样,我们现在只能获得前pression,而不是数据。

It removed the errors, but now the data binding isn't working. Now the output is the expressions and not the actual data. I have also tried putting $scope.$apply() into a $timeout function, but again, now we only get the expression and not the data.

这code是一个指令中。我只给你这code,因为code的指令,其余在这里无关紧要。
什么我需要做的就是数据绑定,同时仍使用$超时工作?

This code is within a directive. I have only given you this code since the rest of the code in the directive is irrelevant here. What do I need to do to get the data binding to work while still using $timeout?

先谢谢了。

编辑:一个重要组成部分,我忘了告诉的是,我认为错误是前2 pressions是空的。在Chrome中调试程序,他们得到了一个未定义。

A vital part I forgot to tell was that I believe that the error is for 2 expressions that are empty. In chrome debugger they get undefined.

推荐答案

你有没有考虑在多棱角兼容的方式实现你的指令,而不是对付$您所拥有的申请?

Have you considered implementing your directive in a more angular compatible way instead of dealing with the $apply on you own?

这样的错误通常会在被角范围外执行了一块code的,如,jQuery的code。

These kind of errors usually come when a piece of code is being executed outside angular context,e.g., jquery code.

我会建议避免的jQuery尽可能多地写你的指令。如果需要的话,可以考虑使用链接功能。

I will suggest avoiding jQuery as much as possible to write your directive. If required, consider using link function.

这篇关于AngularJS $消化正在进行中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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