How to remove from scope when not in use in AngularJS?
angularjs, angularjs-scope
Solution
On http://docs.angularjs.org/api/ng.$rootScope.Scope it mentions that
Just before a scope is destroyed a $destroy event is broadcasted on this scope. Application code can register a $destroy event handler that will give it chance to perform any necessary cleanup.
This seems like exactly what you want.
Problem
I've setup a controller to tick every few seconds, which in turn makes a restful call to a backend api. Everything is working as expected, except when I navigate to another section (handled by a separate controller), the tick continues to fire. Is it possible to remove the controller from scope entirely? Here's a paste of my current controller: ``` myApp.controller('SupervisorController', function($scope, supervisord, $timeout) { $scope.supervisord = supervisord; (function tick() { $scope.supervisord.fetch(); $timeout(tick, 2500); })(); }); ```