Reputation: 1947
I'm using $rootScope.$emit('driver-loader');
once my webservice finished getting data. This is the only place 'driver-loader' gets emitted. Once I do...
var watchDriverLoader = $rootScope.$on('driver-loaded', function(){
console.log('loaded');
watchDriverLoader = null;
});
...inside my controller, that console.log gets called multiple times, sometimes even 4-5 times.
Upvotes: 1
Views: 966
Reputation: 77
You need to destroy $rootScope.$on
manually.
var watchDriverLoader = $rootScope.$on('driver-loaded', function(){
console.log('loaded');
});
$scope.$on('$destroy', watchDriverLoader);
Upvotes: 3