FernandoKahdal / angular-sails

An angular module for using the sails socket.io api

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Angular Sails

This small module allows you to use Sails.JS's awesome socket.io api with AngularJS.

Just add a dependency to your module and controllers and get it going!

Install it:

bower install angular-sails

Usage

A small example:

var app = angular.module("MyApp", ['ngSails']);

app.controller("FooController", function ($scope, $sails) {
  $scope.bars = [];
  
  (function () {
    $sails.get("/bars", function (data) {
      $scope.bars = data;
    });
    
    $sails.on("message", function (message) {
      if (message.verb === "create") {
        $scope.bars.push(message.data);
      }
    });
  }());
});

API Refenrence

Sails.JS REST

Angular Sails wraps the native sails.js REST functions. For further information check out the sails docs and Mike's Screencast

reconnect(url, options)

Angular Sails connects to the current URL by default. Sometimes you need to connect your socket to another URL. You can reconnect your socket connection like this:

  $sails.reconnect('http://foobar.com:1338');

disconnect()

A wrapper for the socket.io disconnect function.

  $sails.disconnect();

emit(event, data)

A wrapper for socket.io's emit function.

  $sails.emit('something very cool', { foo: 'bar' });

About

An angular module for using the sails socket.io api

License:MIT License