T
T
TimZallin2014-02-03 18:19:39
Angular
TimZallin, 2014-02-03 18:19:39

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

3 answer(s)
D
Denis Pushkarev, 2014-02-03
@TimZallin

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
  });
}

S
snackovich, 2014-02-05
@snackovich

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

G
Gazilla, 2015-03-22
@Gazilla

I already figured it out, but after specifying the path to the database, this came out
bde32ac5006e4af6a4f948dfc7b642e9.PNG

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question