Skip to content
프로젝트

소개

An angular module for using the sails socket.io api

웹 및 앱 개발

이 수치를 측정하는 방법

측정된 스타 증가

in 24h
0
in 7 days
0
in 15 days
0
in 1 month
업데이트 지연

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

README.md

Original

Build Status

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

You must also include sails.io.js in order to use this.

Usage

For a more complex example, have a look at the tutorial by Maarten.

A small example:

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

//OPTIONAL! Set socket URL!
app.config(['$sailsProvider', function ($sailsProvider) {
    $sailsProvider.url = 'http://foo.bar';
}]);

app.controller("FooController", function ($scope, $sails) {
  $scope.bars = [];

  (function () {
    // Using .success() and .error()
    $sails.get("/bars")
      .success(function (data, status, headers, jwr) {
        $scope.bars = data;
      })
      .error(function (data, status, headers, jwr) {
        alert('Houston, we got a problem!');
      });

    // Using .then()
    $sails.get("/bars")
      .then(function(resp){
          $scope.bars = resp.data;
      }, function(resp){
        alert('Houston, we got a problem!');
      });

    // Watching for updates
    var barsHandler = $sails.on("bars", function (message) {
      if (message.verb === "created") {
        $scope.bars.push(message.data);
      }
    });
    
    // Stop watching for updates
    $scope.$on('$destroy', function() {
      $sails.off('bars', barsHandler);
    });
    
  }());
});

API Reference

Sails.JS REST

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

Native socket functions

The sails service is nothing more like the native socket.io object!

관련 프로젝트 살펴보기

불러오는 중…