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.
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);
watchExp
changes. The function will be called with two
parameters, newValue
and oldValue
.watchExp
or listener
throws an exception. If a DOMElement is
specified as handler, the element gets decorated by angular with the information about the
exception.