diff --git a/src/ng/compile.js b/src/ng/compile.js index 0274c813a1af..20f384bd8a30 100644 --- a/src/ng/compile.js +++ b/src/ng/compile.js @@ -1188,7 +1188,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { listeners.push(fn); $rootScope.$evalAsync(function() { - if (!listeners.$$inter && attrs.hasOwnProperty(key)) { + if (!listeners.$$inter && attrs.hasOwnProperty(key) && !isUndefined(attrs[key])) { // no one registered attribute interpolation function, so lets call it manually fn(attrs[key]); } diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js index 02ea29cc9545..ef5787b49fa0 100755 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -2991,6 +2991,23 @@ describe('$compile', function() { ); + it('should call observer only when the attribute value changes', function() { + module(function() { + directive('observingDirective', function() { + return { + restrict: 'E', + scope: { someAttr: '@' } + }; + }); + }); + inject(function($rootScope, $compile) { + $compile('')($rootScope); + $rootScope.$digest(); + expect(observeSpy).not.toHaveBeenCalledWith(undefined); + }); + }); + + it('should delegate exceptions to $exceptionHandler', function() { observeSpy = jasmine.createSpy('$observe attr').andThrow('ERROR');