Now I get rid of the dependency $scopeon my angular controller so that I can easily port my code to Angular2. My current version is angular 1.4.X. Performing the same thing, there is a place when I placed a $destroylistener over my area of ββthe controller, for example $scope.$on('$destory', function() ....).
$scope
1.4.X
$destroy
$scope.$on('$destory', function() ....)
I see a method $onavailable only on the $scopecontroller, but how can I achieve it without using a dependency $scope.
$on
angular 1.5+, , . $scope. $onDestroy() , , :
$onDestroy()
$onDestroy() - , . , .
http://blog.thoughtram.io/angularjs/2016/03/29/exploring-angular-1.5-lifecycle-hooks.html:
function MyCmpController($element) { var clickHandler = function () { // do something }; this.$onInit = function () { $element.on('click', clickHandler); }; this.$onDestroy = function () { $element.off('click', clickHandler); }; }
, $destroy DOM, DOM $destroy, , DOM, .
DOM
, $element, , DOM, ng-controller. $element , ,
$element
ng-controller
$element.on('$destroy', function(){ //write clean up code here });
1.4.X. 1.5.3+ Angular lifecycle hook, $onDestroy, @pgreen2 . :)
lifecycle hook
$onDestroy
@pgreen2