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

Commit 47f7bd7

Browse files
fix(rootScope): make stopPropagation only stop its own event
All sibling event handlers residing on the same scope to were stopped if one of them called stopPropagation. Closes #4204
1 parent 9089468 commit 47f7bd7

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/ng/rootScope.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -867,12 +867,14 @@ function $RootScopeProvider(){
867867
continue;
868868
}
869869
try {
870+
//allow all listeners attached to the current scope to run
870871
namedListeners[i].apply(null, listenerArgs);
871-
if (stopPropagation) return event;
872872
} catch (e) {
873873
$exceptionHandler(e);
874874
}
875875
}
876+
//if any listener on the current scope stops propagation, prevent bubbling
877+
if (stopPropagation) return event;
876878
//traverse upwards
877879
scope = scope.$parent;
878880
} while (scope);

test/ng/rootScopeSpec.js

+8
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,14 @@ describe('Scope', function() {
10601060
expect(log).toEqual('2>1>0>');
10611061
});
10621062

1063+
it('should allow all events on the same scope to run even if stopPropagation is called', function(){
1064+
child.$on('myEvent', logger);
1065+
grandChild.$on('myEvent', function(e) { e.stopPropagation(); });
1066+
grandChild.$on('myEvent', logger);
1067+
grandChild.$on('myEvent', logger);
1068+
grandChild.$emit('myEvent');
1069+
expect(log).toEqual('2>2>2>');
1070+
});
10631071

10641072
it('should dispatch exceptions to the $exceptionHandler',
10651073
inject(function($exceptionHandler) {

0 commit comments

Comments
 (0)