Skip to content
This repository has been archived by the owner on Apr 13, 2022. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
fix($compile): don't trigger $observer if initial value is undefined
Closes #12383
Closes #12464
  • Loading branch information
petebacondarwin committed Jul 30, 2015
1 parent 97ac763 commit 6f3b862
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ng/compile.js
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
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

0 comments on commit 6f3b862

Please sign in to comment.