Comments (3)
Yep, this is an issue. You can listen to $scope.$on('$destroy', ...)
. See: http://docs.angularjs.org/api/ng.$rootScope.Scope#Events
I'll try to update the example/blog post with more info when I get a chance.
from angular-socket-io-seed.
hi how do we use $scope.$on('$destroy', ...) code to prevent the multiple event emitted problem?
actually thats what i did:
in my controller:
$scope.$on('$destroy', function (event) {
//socket.removeAllListeners();
socket.removeAllListeners();
//console.log('destroy triggered!');
});
And my socket factory is now updated to this:
app.factory('socket', function ($rootScope) {
var socket = io.connect('http://dils.biz:3006');
return {
removeAllListeners: function (eventName, callback) {
socket.removeAllListeners();
},
on: function (eventName, callback) {
socket.on(eventName, function () {
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);
}
});
})
}
};
});
from angular-socket-io-seed.
The service is now implemented in a separate repo.
Please continue this discussion here: btford/angular-socket-io#3
from angular-socket-io-seed.
Related Issues (17)
- no method "address" HOT 2
- Question about the api.js in routes folder HOT 2
- $scope.messages needs declaration HOT 1
- In "btford.socket-io" module why use $rootScope.$apply() in emit() while using $timeout in on() HOT 3
- Add Mongoose HOT 1
- Address from socket HOT 1
- unhandled socket.io url HOT 2
- ReferenceError: io is not defined HOT 5
- Upgrade to Express 3.x HOT 1
- `!!!` is deprecated, you must now use `doctype`
- Update the tutorial that spawned this repo
- client socket.emit('send:message', {message:msg}); not work
- testing HOT 10
- Update to 1,0.4 HOT 1
- Why it isn't come with test suite setup? HOT 2
- jQuery UI Layout Plug-in HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angular-socket-io-seed.