Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mbenford/ngSocketIO
Simple Socket.IO module for AngularJS
https://github.com/mbenford/ngSocketIO
Last synced: 4 months ago
JSON representation
Simple Socket.IO module for AngularJS
- Host: GitHub
- URL: https://github.com/mbenford/ngSocketIO
- Owner: mbenford
- License: mit
- Created: 2013-06-27T05:01:59.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2013-11-10T03:30:34.000Z (about 11 years ago)
- Last Synced: 2024-06-22T21:11:37.948Z (6 months ago)
- Language: JavaScript
- Homepage:
- Size: 330 KB
- Stars: 114
- Watchers: 7
- Forks: 24
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
ngSocketIO
===========
[![Build Status](https://travis-ci.org/mbenford/ngSocketIO.png?branch=master)](https://travis-ci.org/mbenford/ngSocketIO)Socket.IO module for AngularJS
## Requirements
- AngularJS 1.0.5+
- Socket.IO 0.9.16## Installing
Simply download either `ng-socket-io` or `ng-socket-io.min.js` from the build folder and add it to your web application. Just make sure it's included after the AngularJS script.
## Usage
1. Add the `socket-io` module as a dependency in your AngularJS app;
2. Inject the `socket` factory wherever you need to use Socket.IO;
3. You're done!## Example
var myApp = angular.module('myApp', ['socket-io']);
myApp.controller('MyCtrl', function($scope, socket) {
// Listening to an event
socket.on('someEvent', function(data) {
$scope.data = data;
});// Raising an event
$scope.raise = function(message) {
socket.emit('otherEvent', message);
};
});
## Cancelling a subscription automatically on scope destructionIf you want to unsubscribe from an event automatically on scope destruction, just call `bindTo` passing the current scope:
socket.on('someEvent', function(data) {
...
}).bindTo($scope);