Сам контроллер (socket.removeAllListeners не помог, пробовал вызывать без eventName):
.controller('chatNotificationCtrl', ['$scope', 'socket', 'toastr', '$http', function($scope, socket, toastr, $http) {
$scope.chatNotifications = {};
if ($scope.logged) {
$scope.chatNotifications = $scope.logged.chatNotify;
} else {
return;
}
console.log('STARTED');
socket.on('notify:chat', function(data) {
console.log('NOTIFY CHAT');
$scope.chatNotifications.unshift(data);
toastr.success('Example', 'New Message');
});
$scope.$on('$destroy', function() {
console.log('!!!!!!!!!!!!')
socket.removeAllListeners('notify:chat');
});
}])
И Фабрика :
.factory('socket', ['$rootScope', function($rootScope) {
var socket = io.connect();
return {
id: socket.id,
on: function(eventName, callback) {
socket.on(eventName, function() {
console.log(socket);
var args = arguments;
$rootScope.$apply(function() {
callback.apply(socket, args);
});
});
},
emit: function(eventName, data, callback) {
socket.emit(eventName, data, function() {
var args = arguments;
$rootScope.$apply(function() {
if (callback) {
callback.apply(socket, args);
}
});
})
},
removeAllListeners: function(eventName, callback) {
socket.removeAllListeners(eventName, function() {
var args = arguments;
$rootScope.$apply(function() {
callback.apply(socket, args);
});
});
}
};
}])