mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-22 21:25:47 +00:00
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
This commit is contained in:
parent
9089468092
commit
47f7bd706e
2 changed files with 11 additions and 1 deletions
|
|
@ -867,12 +867,14 @@ function $RootScopeProvider(){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
//allow all listeners attached to the current scope to run
|
||||||
namedListeners[i].apply(null, listenerArgs);
|
namedListeners[i].apply(null, listenerArgs);
|
||||||
if (stopPropagation) return event;
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
$exceptionHandler(e);
|
$exceptionHandler(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//if any listener on the current scope stops propagation, prevent bubbling
|
||||||
|
if (stopPropagation) return event;
|
||||||
//traverse upwards
|
//traverse upwards
|
||||||
scope = scope.$parent;
|
scope = scope.$parent;
|
||||||
} while (scope);
|
} while (scope);
|
||||||
|
|
|
||||||
|
|
@ -1060,6 +1060,14 @@ describe('Scope', function() {
|
||||||
expect(log).toEqual('2>1>0>');
|
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',
|
it('should dispatch exceptions to the $exceptionHandler',
|
||||||
inject(function($exceptionHandler) {
|
inject(function($exceptionHandler) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue