From 47f7bd706efc5f2944d182e46c1b1d324298ff36 Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Sat, 5 Oct 2013 22:45:43 +0100 Subject: 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 --- src/ng/rootScope.js | 4 +++- test/ng/rootScopeSpec.js | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/ng/rootScope.js b/src/ng/rootScope.js index 08a2eff5..48f8a07b 100644 --- a/src/ng/rootScope.js +++ b/src/ng/rootScope.js @@ -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); diff --git a/test/ng/rootScopeSpec.js b/test/ng/rootScopeSpec.js index e8bf8eed..894c26d2 100644 --- a/test/ng/rootScopeSpec.js +++ b/test/ng/rootScopeSpec.js @@ -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) { -- cgit v1.2.3