i have socket.io as service which works in angularJS but i trying to reimplement it as service in angular. any idea on how to:
here is the implementation in angularJS:
angular.module('App')
.factory('socket', function ($rootScope) {
var socket = io.connect()
return {
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)
}
})
})
}
}
})