When , where and how to get rid of old event listeners when the controller is no longer suitable?
Consider a SPA with two routes: /login and /loggedin
app.factory('socket', ['$window', function(window) { return window.io(); }]); app.controller('loginController', ['socket', function (socket) { this.tryLogin = function(credentials) { socket.emit('login', credentials); } sokcet.on('loginResponse', function(data) { if (data.status == 'OK') {
Problems:
- When switching to
/loggedin event continues to be listened - When you go back to the
/login page, a new listener (in fact, I now have 2 listeners)
source share