How often does the AngularJS digest loop run?

后端 未结 3 1803
无人及你
无人及你 2021-02-02 08:03

When discussing the merits of AngularJS, two-way data binding is often touted as a major benefit of Angular over other JS frameworks. Digging deeper, the documentation suggests

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-02 08:30

    Angular digests are triggered - they don't happen through polling.

    Code executes, after code is done, angular triggers a digest.

    Example:

     element.on('click', function() {
         $scope.$apply(function() { 
             // do some code here, after this, $digest cycle will be triggered
         });
     });
    

    Angular will also trigger a $digest after the compile/link phase:

    Compile > Link > Digest
    

    And as to how many digest cycles are triggered? It depends on how soon the scope variables stabalise. Usually it takes at least 2 cycles to determine that.

提交回复
热议问题