常梦网 常梦网

angular-sails

时间: 2024-01-18  热度:

11月23日开源中国源创会年度(北京万豪酒店)千人盛典正在报名中

angular-sails 是使用 Sails Socket.io API 的 AngularJS 模块。

据说,用了 Angular-sails,从此告别 Ajax!

安装

bower install angular-sails

使用示例

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 () {    $sails.get("/bars")      .success(function (data) {        $scope.bars = data;      })      .error(function (data) {        alert('Houston, we got a problem!');      });    $sails.on("message", function (message) {      if (message.verb === "create") {        $scope.bars.push(message.data);      }    });  }());});

相关阅读