Skip to content

Commit

Permalink
fix(rootScope): make stopPropagation only stop its own event
Browse files Browse the repository at this point in the history
All sibling event handlers residing on the same scope to were stopped
if one of them called stopPropagation.

Closes angular#4204
  • Loading branch information
petebacondarwin authored and jamesdaily committed Jan 27, 2014
1 parent 9a0ea9e commit 279bf6c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/ng/rootScope.js
Original file line number Diff line number Diff line change
Expand Up @@ -867,12 +867,14 @@ function $RootScopeProvider(){
continue;
}
try {
//allow all listeners attached to the current scope to run
namedListeners[i].apply(null, listenerArgs);
if (stopPropagation) return event;
} catch (e) {
$exceptionHandler(e);
}
}
//if any listener on the current scope stops propagation, prevent bubbling
if (stopPropagation) return event;
//traverse upwards
scope = scope.$parent;
} while (scope);
Expand Down
8 changes: 8 additions & 0 deletions test/ng/rootScopeSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,14 @@ describe('Scope', function() {
expect(log).toEqual('2>1>0>');
});

it('should allow all events on the same scope to run even if stopPropagation is called', function(){
child.$on('myEvent', logger);
grandChild.$on('myEvent', function(e) { e.stopPropagation(); });
grandChild.$on('myEvent', logger);
grandChild.$on('myEvent', logger);
grandChild.$emit('myEvent');
expect(log).toEqual('2>2>2>');
});

it('should dispatch exceptions to the $exceptionHandler',
inject(function($exceptionHandler) {
Expand Down

0 comments on commit 279bf6c

Please sign in to comment.