mgilson
mgilson

Reputation: 310089

angular.Scope.Event.stopPropagation not present

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

Answers (1)

mgilson
mgilson

Reputation: 310089

It turns out that stopPropagation is only available for events created via scope.$emit, not scope.$broadcast.

From the documentation:

stopPropagation - {function=}: calling stopPropagation function will cancel further event propagation (available only for events that were $emit-ed).

Upvotes: 3

Related Questions