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

fix($compile): don't trigger $observer if initial value is undefined #12464

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ng/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand Down
17 changes: 17 additions & 0 deletions test/ng/compileSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('<observing-directive observer></observing-directive>')($rootScope);
$rootScope.$digest();
expect(observeSpy).not.toHaveBeenCalledWith(undefined);
});
});


it('should delegate exceptions to $exceptionHandler', function() {
observeSpy = jasmine.createSpy('$observe attr').andThrow('ERROR');

Expand Down