angular.js - What is $root.$$phase in angularjs?
伊谢尔伦
伊谢尔伦 2017-05-15 16:49:29
0
1
674

There is the following ng code:

$scope.safeApply = function(fn){
   var phase = this.$root.$$phase;
   if (phase == '$apply' || phase == '$digest') {
       if (fn && ( typeof (fn) === 'function')) {
          fn();
       }
   } else {
       this.$apply(fn);
   }
}

The meaning of this code should be to say whether it is necessary to call scope.$apply() to execute the function fn. If not, call fn directly. If necessary, call scope.$apply(fn).. .
However, I want to know what $root.$$phase is and why it can be used to determine whether $apply needs to be executed. I hope someone who understands the ng principle can help answer it~ Thank you~~~

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(1)
世界只因有你

$$phase is a status flag used internally by angluar to identify whether it is currently in the digest state.

Usually there is no need to care about this status in the program (two $ 打头更说明它是内部使用的),如果你写出了需要关心这个状态的代码,比如这个 safeApply, then there must be something wrong.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template