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
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);
}
});
}());
});
Angular Sails wraps the native sails.js REST functions. For further information check out the sails docs and Mike's Screencast
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');
A wrapper for the socket.io disconnect function.
$sails.disconnect();
A wrapper for socket.io's emit function.
$sails.emit('something very cool', { foo: 'bar' });