Skip to content

Commit

Permalink
fix($compile): don't trigger $observer if initial value is undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
petebacondarwin authored and netman92 committed Aug 8, 2015
1 parent 1194390 commit e1b9810
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
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

0 comments on commit e1b9810

Please sign in to comment.