In one controller I do :
$rootScope.$emit("newAction", {});
in another controller I do :
$rootScope.$on('newAction', function() {
vm.newAction (...);
vm.newAction (...);
vm.newAction (...);
vm.newAction (...);
vm.newAction (...);
vm.newAction (...);
});
My problem is that $rootScope.$on is called multiple times. I don't know why.
If anybody has a hint... Thanks
$rootScope
listener are not destroyed automatically. You need to destroy it using $destroy
.
var customeEventListener = $rootScope.$on('newAction', function() {
vm.newAction (...);
vm.newAction (...);
vm.newAction (...);
vm.newAction (...);
vm.newAction (...);
vm.newAction (...);
});
$scope.$on('$destroy', function() {
customeEventListener();
});
Refer this link
Working with $scope.$emit and $scope.$on
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With