Now I'm getting rid of $scope dependency from my angular controller to ensuring that I could easily migrate my code to Angular2. My current angular version is 1.4.X.
While doing the same thing there is place while I placed $destroy listener over my controller scope like $scope.$on('$destory', function() ....).
I can see $on method only available on $scope of controller, but how can I achieve it without using $scope dependency.
If you are using angular 1.5+ they added lifecycle hooks that you can opt into on your controller. No
$scopeneeded. Just add a function called$onDestroy()to your controller and it will be called when your controller is being clean up:Example from http://blog.thoughtram.io/angularjs/2016/03/29/exploring-angular-1.5-lifecycle-hooks.html: