有没有办法去抖动$摘要(由外部调用触发)

时间:2017-11-15 13:40:59

标签: angularjs angular-digest

我想去除一个巨大角度应用程序的摘要。

我有很多来自http电话的更新,我想避免每次触发一次摘要,但每XXX最多一次。

例如,使用以下代码:

HTML

<div ng-app="myApp">
  <div ng-controller="Ctrl as ctrl">
    counter value : {{ctrl.counter}} - Should be 100 at the end of the process <br>
    Digests count : <span id="digest-counter"></span> - Should be as low as possible
  </div>
</div>

JS

let digestsCounter = 0;

angular.module('myApp', []);

angular.module('myApp').controller('Ctrl', ($log, $timeout, $rootScope) => {

$rootScope.$watch(() => {
digestsCounter += 1;
document.getElementById('digest-counter').innerHTML = digestsCounter;
});
this.counter = 0;
for(let i = 0 ; i < 100 ; ++i) {
$timeout(() => {this.counter += 1}, 10 * i);
}

return this;
});

我最后得到了:

counter value : 100 - Should be 100 at the end of the process 
Digests count : 202 - Should be as low as possible

如何去除摘要以避免202摘要?

这是一个fiddle,上面的代码说明了我的问题。

0 个答案:

没有答案