While optimizing my Angular application and researching various websites, I came across this practice:
var cleanup = $scope.$on('someEvent', function() {
$scope.refresh();
});
$scope.$on('$destroy', function() {
cleanup();
});
Considering that I have multiple $scope.$on
statements in my controllers, I am curious if utilizing the following approach is acceptable:
var first = $scope.$on('firstEvent', function() {
$scope.something1();
});
var second = $scope.$on('secondEvent', function() {
$scope.something2();
});
var third = $scope.$on('thirdEvent', function() {
$scope.something3();
});
$scope.$on('$destroy', function() {
first();
second();
third();
});
Is this a recommended and proper implementation?