I'm just wondering if any $scope.$watch/$scope.$watchCollection/$scope.$on are automatically deregistered when the $destroy event is called on the $scope. I see that they all return a deregister function and I'm wondering if it's good practive to call those functions on a $scope destroy event or will Angular do that itself. I do it for performance reasons right now, but if this happens automatically then I will stop calling those functions directly.
Asked
Active
Viewed 711 times
1 Answers
2
If you are listening for $destroy event it means that your $scope
is going to be destroyed so all $watches will be removed automatically so you don't need to, that's why it's always better to register $watches at current $scope
and not at $rootScope
(since those will persist as long as the app is running or you deregister manually). Same thing If you are calling the $destroy
event/method yourself.

Wawy
- 6,259
- 2
- 23
- 23