Closed royling closed 9 years ago
I like this idea better. The original looks like I am attaching unique handlers to each rootListener. Why not just one catch all?
Just updated it, I've been using an Array instead of Object lately, so added this syntax:
var unbind = [
$rootScope.$on('customEvent1'[, callback]),
$rootScope.$on('customEvent2'[, callback]),
$rootScope.$on('customEvent3'[, callback])
];
$scope.$on('$destroy', function () {
unbind.forEach(function (fn) {
fn();
});
});
In event pub/sub section, why do we unbind listener within multiple $destroy event binding?
Can we do this instead? move for loop into the $destroy event handler