angularjs - How to watch a function return value in JavaScript -


in browser, object, property has getter , setter. can override them watch attribute. how return value of function? in angularjs, use 'ng-show' control visibility of component. can write this:

<any ng-show="afunction()"> ... </any> 

the function may defined as:

var tmp = false; $scope.afunction = function() { return tmp; }; 

if in runtime, 'tmp' changed true, < > show up. how angularjs know return value changed? there timeout function check changes regularly?

there no timeout function. there angularjs-specific concept, called "digest-cycle".
can learn more scope life-cycle docs.
have found this article quite useful introduction mechanism.
finally, sure there plenty of related answers here on so.

in general, should try find out functions $apply(), $digest(), $watch() do.


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

c# - Unity IoC Lifetime per HttpRequest for UserStore -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -