angular.scope.$watch

Work in Progress This page is currently being revised. It might be incomplete or contain inaccuracies.

Description

Registers listener as a callback to be executed every time the watchExp changes. Be aware that callback gets, by default, called upon registration, this can be prevented via the initRun parameter.

Example

         var scope = angular.scope();
         scope.name = 'misko';
         scope.counter = 0;

         expect(scope.counter).toEqual(0);
         scope.$watch('name', 'counter = counter + 1');
         expect(scope.counter).toEqual(1);

         scope.$eval();
         expect(scope.counter).toEqual(1);

         scope.name = 'adam';
         scope.$eval();
         expect(scope.counter).toEqual(2);
       

Dependencies

Usage

angular.scope.$watch(watchExp, listener[, exceptionHanlder][, initRun]);

Parameters