In my application, I have a controller class serving as the state controller. In the constructor of this controller class, I've registered a setInterval() method to call a service every 30 seconds.
export default class abc {
constructor() {
setInterval(() => {
// Call to service class here
}, 30000 );
}
}
The issue I'm facing now is that even when the state changes, the service call continues to happen. I believe clearInterval() method should be used to stop this but I am unsure how to implement it. Since this is not a component, I cannot use $ondestroy(). I also prefer not to resort to using event listeners for state change. Is there an alternative approach, like a destructor or similar mechanism, that can help me unregister the setInterval? My project involves angular-ui-router with ES6 syntax. Any guidance would be greatly appreciated.