btford / btford/angular-socket-io
doesn't remove or empty array on listener after change route
- Dominant language
- JavaScript
- Stars
- 1.5k
- Forks
- 225
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
I defined a service like this:
```
'use strict';
app.factory('mySocket', function(socketFactory) {
return socketFactory({
ioSocket: io.connect(':3001',{forceNew: true})
});
});
```
and in controller:
```
app.controller('ChatCtrl',function($scope, mySocket,$rootScope) {
$scope.arr = [];
$scope.arr.length = 0;
$scope.currentChannel = 1;
Restangular.all('chat/message/').getList().then(function (data) {
$scope.arr[$scope.currentChannel] =data;
mySocket.on('connect', function () {
console.log('CONNECT');
mySocket.on('messages.new', function (data) {
var tmp = data;
tmp.timestamp = data.timestamp.date;
$scope.arr[data.thread].push(tmp);
})
})
```
when I refresh page all things is okay, but when I switch to another page and come back to chat page `$scope.arr` not null and last data array in listener is exist.
What should I do for null array after come back to chat page (just on listener block)?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.