I have a $rootScope.$on code on top of a controller. I noticed that everytime I load/call this controller, the $rootScope.$on listener increases meaning it will add and add and add a listener, indefinitely as you visit the controller.
I noticed it when I called it via $rootScope.$emit from another controller, the function inside the $rootScope.$on got executed several times even if it was only a single emit/broadcast.
$rootScope.$on('listen', function() {
$scope.displayString();
});
$scope.displayString = function() {
console.log('test'); // This display 7 times because I visit the controller 7 times
}
Is it possible to prevent it from creating another listener instance so that when there is already a listener, it won't create a new one.