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

Fix for event.stopPropagation() and $emit method #3639

Closed
wants to merge 10 commits into from
4 changes: 3 additions & 1 deletion src/ng/rootScope.js
Original file line number Diff line number Diff line change
Expand Up @@ -836,12 +836,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 @@ -922,6 +922,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