what is difference between in angularjs
$apply()
, $digest()
and $watch()
?
Please use below tool to explain if it is possible
what is difference between in angularjs
$apply()
, $digest()
and $watch()
?
Please use below tool to explain if it is possible
Basically these three are different.
When You want to watch a variable. It means if you want, On change of a variable some code should be executed.then you will use watch.
Syntax $watch('variableName',function());
For example, On your page you have a variable which have some value and on change on that value from server or any other source you want to update it then you can apply watch on it. In your function you can write the code which will update the value.
$digest :- Angular internally uses this method. $digest will iterate all the watches and if its find the values of any variable is changed then it will execute the respective function. we can also call this in our code.
$apply :- when we want some code is executed and after that $apply should be executed then we can call $apply.This will execute the code n internally when $apply will be excute then it will be call $digest.