Answer the question
In order to leave comments, you need to log in
How to make Angular remove all socket.io listener's only on controller reload?
Tell me, maybe there is some kind of event, like "controller reload" or something similar.
.controller('chatNotificationCtrl', ['$scope', 'socket', 'toastr', '$rootScope', '$state', function($scope, socket, toastr, $rootScope, $state) {
alert('REFRESHED')
$scope.chatNotifications = {};
console.log('STARTED NOTIFICATION CONTROLLER');
if ($scope.logged) {
$scope.chatNotifications = $scope.logged.chatNotify;
} else {
return;
}
socket.on('notify:chat', function(data) {
console.log('NOTIFY CHAT');
$scope.chatNotifications.unshift(data);
toastr.success('Example', 'New Message');
});
$rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams) {
socket.getSocket().removeAllListeners();
})
}])
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question