Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 6f3b862

Browse files
fix($compile): don't trigger $observer if initial value is undefined
Closes #12383 Closes #12464
1 parent 97ac763 commit 6f3b862

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/ng/compile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
11881188

11891189
listeners.push(fn);
11901190
$rootScope.$evalAsync(function() {
1191-
if (!listeners.$$inter && attrs.hasOwnProperty(key)) {
1191+
if (!listeners.$$inter && attrs.hasOwnProperty(key) && !isUndefined(attrs[key])) {
11921192
// no one registered attribute interpolation function, so lets call it manually
11931193
fn(attrs[key]);
11941194
}

test/ng/compileSpec.js

+17
Original file line numberDiff line numberDiff line change
@@ -2991,6 +2991,23 @@ describe('$compile', function() {
29912991
);
29922992

29932993

2994+
it('should call observer only when the attribute value changes', function() {
2995+
module(function() {
2996+
directive('observingDirective', function() {
2997+
return {
2998+
restrict: 'E',
2999+
scope: { someAttr: '@' }
3000+
};
3001+
});
3002+
});
3003+
inject(function($rootScope, $compile) {
3004+
$compile('<observing-directive observer></observing-directive>')($rootScope);
3005+
$rootScope.$digest();
3006+
expect(observeSpy).not.toHaveBeenCalledWith(undefined);
3007+
});
3008+
});
3009+
3010+
29943011
it('should delegate exceptions to $exceptionHandler', function() {
29953012
observeSpy = jasmine.createSpy('$observe attr').andThrow('ERROR');
29963013

0 commit comments

Comments
 (0)