问题标签 [angularjs-digest]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
0 回答
48 浏览

javascript - 角度 $digest() 问题?

我有一个按钮可以在真假之间切换范围变量:

模板:

控制器:

在控制器中,我还有一个以 200ms 的间隔调用的函数:

如果范围变量“block”为假,则间隔调用的 scaleHeadar 函数应仅通过 if 条件运行。这将给出“____false”的控制台日志和另一个说法“缩放”。

问题在于,当 scope.block 设置为 True 时,scaleHeader 函数仍会经历不应发生的 if 条件。

当块设置为假时,我希望控制台日志为“____true”,就是这样。我得到的是以下控制台日志:

不明白“____false”日志如何出现在两者之间。也许与 $digest() 有关?

对于可能不正确的标题或缺乏表达问题的能力,我们深表歉意!

0 投票
1 回答
144 浏览

javascript - Angular model variable updating too early before DOM updates, causing UI to be "behind"?

I'm trying to build an Angular Tag Directive that functions not too dissimilarity from Stack Overflow's Tag input form. It uses a div with a border to create the illusion of a form, and then a div containing a list of tags to the left of an input field where you can type:

Please note I'm using [[]] as my interpolation provider for Angular because I have another templating engine already using {{}}.

When a key is pressed in the input, it runs a function to check if the key is a backspace or enter or a space to create/remove a tag:

The bit I'm having problems with is the last line before the return statement. What it is meant to do is recompute the width of the .tag-wrapper element and adjust the width of the input element to suit via this ng-style property:

However, as it currently stands, the input length is always one step behind the UI, causing the input to overflow. This is because:

  1. It firstly adds a new tag onto the selectedTags list.
  2. It computes the width of .tag-wrapper.
  3. It returns true letting the original key event pass through
  4. Angular's digest cycle runs and appends a new tag into the DOM. The width of .tag-wrapper is now bigger, and the input overflows.

Here is an example of this:

enter image description here

Right now, step 4 is happening after step 2. I need step 2 to happen after step 4.

How can I achieve this?

0 投票
0 回答
75 浏览

javascript - Angularjs,Ivh-tree:Angularjs 的摘要循环

我在两个最终形成 ivh-treeview 的数组之间切换需要大量时间;两个数组都相差 1000 个元素,一旦页面由对 json 的 restangular 请求加载,我最初将数据加载到数组中。在分析更改数据请求后,使用
Profile->Flare Chart,我看到 $scope.apply()、$scope 和 $digest 的重复循环。我如何减少这个时间?或者我们可以跳过 apply()/digest() 的循环,因为我确定没有隐含的数据依赖?

以下是延迟在 3 毫秒到 8 毫秒之间的耀斑图图像的链接:

在此处输入图像描述

0 投票
1 回答
779 浏览

angularjs - AngularJS:ng-repeat 给出 $rootscope.infdig 错误(无限循环)

首先..对不起长代码,但我想澄清一些。(我的问题位于底部)

我正在尝试获取 1 个客户的所有联系人,首先我尝试在 HTML 代码中getContacts(customer.id)调用该函数。ng-repeat directive但这导致了一个 inifine 循环($rootscope.infdig)。

所以我把函数移到了,ng-init directive但现在我收到了这个错误:

意外的令牌 <

索引.html

客户服务.js

这是一个 javascript 文件,我从 Mysql 数据库中获取一些数据(通过 PHP 文件)

客户控制器.js

我试图 console.loggetContactsByCustomersId()函数的返回值,但它显示如下:d {$$state: Object}

我的问题:'如何访问getContactsByCustomersId()函数的返回数据并在我的 html 代码中使用它???

请问我是否还不够清楚!提前致谢 !!

0 投票
1 回答
619 浏览

javascript - 角度范围不绑定

我有一个这样的模板:

在控制器中,它看起来像:

绑定在回调中不起作用。为什么这样?

0 投票
2 回答
75 浏览

javascript - $scope.$apply() 调用是否适用于这种情况?

AngularJS(坦率地说是 JavaScript)的新手,但从我收集的信息来看,只有在 Angular 的雷达之外发生更改时才需要显式调用 $scope.$apply() 。下面的代码(从这个 plunker粘贴)让我认为这不是需要调用的情况,但这是我让它工作的唯一方法。我应该采取不同的方法吗?

索引.html:

脚本.js:

0 投票
1 回答
116 浏览

jquery - 将 div 点击事件链接到角度过滤器复选框

我正在使用基于this jsfiddle中的一个角度复选框过滤器(来自另一个问题)。http://jsfiddle.net/rzgWr/502/

我不想使用默认复选框,所以我使用 jquery 将两个 div“链接”到复选框,如下所示:

我的 jquery 可以与 html 一起正常工作并选中该框,但是 angular 模型没有检测到更改并且无法“刷新”本身(摘要?)以更新过滤后的输出(有关上下文,请参见 jsfiddle)。

我需要添加什么来确保角度模型能够检测到点击,或者检测到复选框状态中 jquery 所做的更改?我是否将更改写入 jquery 文件或角度控制器?

我知道使用 jquery 和 angular 会很麻烦,所以如果有一个 angular-only 选项,请赐教。

0 投票
1 回答
227 浏览

angularjs - 为什么这种排序会导致无限的摘要错误?

这是架构:我有一个控制器和一个服务。控制器可以调用服务并对其数据进行排序。我有一个服务方法setSort,它只是在服务中设置一个变量。控制器监视服务中的数据。如果排序处于活动状态,我会收到无限摘要错误。演示: http: //jsbin.com/berujec/edit ?js,output

要重现infdig错误:

  1. 打开控制台。
  2. 单击切换排序。

是什么导致无限摘要发生?

0 投票
0 回答
161 浏览

angularjs - 在滚动事件上禁用 ng-class 更新

我尝试在每个滚动事件中禁用 ng-class reevulating。当我尝试实现一个地址簿时,这尤其痛苦,其中每个字母表都通过 ng-class 检查它是否处于活动状态:

字母表是:

和alphabetIsActive:

在每个滚动事件中重新调用上述代码是很疯狂的,即使在台式计算机上也有明显的延迟。

我知道这种ng-class="::{active: alphabetIsActive(a)}"形式,但它完全扼杀了交互性,ng-class 永远不会更新。(甚至没有点击事件)。

$scope.mainList就我而言,我只需要在列表(变量)更改时重新调整所选字母表。

0 投票
1 回答
146 浏览

angularjs - PhoneGap、Iphone、Angular 摘要循环错误:[$rootScope:infdig]

我有一个在我的浏览器上运行良好的 Angular 应用程序。(也是我 iphone5 的浏览器)只有当我使用 PhoneGap 在手机上运行它时才会出现问题。

是每次我在视图之间移动(我的应用程序中的 ALL VIEW)我都会收到类似的错误...

1)在我手机的浏览器中,我没有收到任何错误

2)我根本没有使用 $scope.$watch

3) 我禁用了 FastClick

4) 视图中的所有数据都来自保存静态 JSON 的服务,例如:

但是每次我在视图之间移动时都会收到此错误

你能帮我吗