Answer the question
In order to leave comments, you need to log in
How to integrate angular.js and socket.io?
I recently started learning angular, the question arose of how to make it friends with socket.io.
I saw several English-language tutorials, but they did not bring any clarity.
Dear professionals, help a newbie.
Answer the question
In order to leave comments, you need to log in
We wrap it in a service, we weigh $rootScope.$apply to execute callbacks.
An example of a service is here: www.html5rocks.com/en/tutorials/frameworks/angular...
Then we use it as usual:
function controller($scope, socket){
socket.emit('getFoo', 42, function(data){
$scope.foo = data
});
}
I slightly changed the service from the top answer
https://gist.github.com/Vitaliy-Yarovuy/8815316
because it contains an error, it can be detected when sending more than 2 arguments
to the service method, a number of libraries both on the backend and on the frontend not limited to 2 arguments when sending messages
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question