Reputation: 310089
In testing my app with Jasmine/Karma, I noticed some interesting behavior when handling scope events:
$scope.$on('some-event', function(event) {
event.stopPropagation();
});
Then in my test I broadcasted the event from the $rootScope
:
$rootScope.$broadcast('some-event');
This resulted in a TypeError
:
TypeError: event.stopPropagation is not a function
at null.<anonymous>
...
Upvotes: 2
Views: 767
Reputation: 310089
It turns out that stopPropagation
is only available for events created via scope.$emit
, not scope.$broadcast
.
From the documentation:
stopPropagation
- {function=
}: callingstopPropagation
function will cancel further event propagation (available only for events that were$emit
-ed).
Upvotes: 3