From 7da2bdb82a72dffc8c72c1becf6f62aae52d32ce Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Sat, 21 Jan 2012 00:01:44 -0800 Subject: fix(scope): support watching functions currently we run into infinite digest if a function is being watched as an expression. This is because we generate bound function wrapper when the watch is processed via parser. I'm not too keen on the solution because it relies on the unbound fn that is being exposed for other reasons, but I can't think of a better way to deal with this right now --- test/service/scopeSpec.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'test/service') diff --git a/test/service/scopeSpec.js b/test/service/scopeSpec.js index 30805684..b1b870f4 100644 --- a/test/service/scopeSpec.js +++ b/test/service/scopeSpec.js @@ -248,6 +248,22 @@ describe('Scope', function() { })); + it('should watch functions', function() { + module(provideLog); + inject(function($rootScope, log) { + $rootScope.fn = function() {return 'a'}; + $rootScope.$watch('fn', function(scope, fn) { + log(fn()); + }); + $rootScope.$digest(); + expect(log).toEqual('a'); + $rootScope.fn = function() {return 'b'}; + $rootScope.$digest(); + expect(log).toEqual('a; b'); + }) + }); + + it('should prevent $digest recursion', inject(function($rootScope) { var callCount = 0; $rootScope.$watch('name', function() { -- cgit v1.2.3