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

fix(event.stopPropagation()): sibling event handlers should not be cancelled by event.stopPropagation() #4204

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
4 changes: 3 additions & 1 deletion src/ng/rootScope.js
Original file line number Diff line number Diff line change
Expand Up @@ -864,12 +864,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 @@ -1046,6 +1046,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