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
Post a Comment