What does angular $watch do when no return value from the function it monitor

132 Views Asked by At

All:

I am pretty new to Angular, when I tried to understand how ngStorage works, there is some code in its source like:

$rootScope.$watch(function() {
    _debounce || (_debounce = $timeout($storage.$apply, 100, false));
});

From Angular Scope Doc:

$watch(watchExpression, listener, [objectEquality]);

Expression that is evaluated on each $digest cycle. A change in the return value triggers a call to the listener.

string: Evaluated as expression

function(scope): called with current scope as a parameter.

Both ways need some return value to trigger a listener, but in this example, there is no return value nor listener, so I kinda wondering what this code do?

Or if anyone could briefly talk about how ngStorage works?

Thanks

0

There are 0 best solutions below