Shawn Shawn - 1 year ago 98
AngularJS Question

Angular UI Router 1.0 - why $scope.$watch('$destroy') is called without leaving state?

Check the plunker here:

As far as I know,

should be called when $scope is about to be destroyed.

The example above shows that when entering into a state, it's
is called right away. Why is that?

Answer Source

Instead of:

$scope.$watch('$destroy', ... 

We should use

$scope.$on('$destroy', ...
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download