Giter Site home page Giter Site logo

Comments (3)

btford avatar btford commented on June 14, 2024

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.

michaeljoser avatar michaeljoser commented on June 14, 2024

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.

btford avatar btford commented on June 14, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.