I have an Angular controller, a fairly simple one:
angular.controller('appCtrl', function ($scope, $rootScope) {
$rootscope.$on('channel.message', function () {
// do stuff here
}
});
I have some sidebar on my page, which navigates me to a view attached to controller as above.
The issue is that each time I click on a link, Angular instantiates the controller - that's totally fine, but I can see that the count of subscribers for my 'channel.message'
is growing, which is not what I want.
I understand that, well, code just adds another callback to queue, but I'm looking to avoid that issue. I want only a single subscriber. What are best practices here?
BTW: I know about $scope.$on. It doesn't count because of performance implications and architecture design of the app itself.