angular集成websocket_angular-websocket.js 使用

何灼光
2023-12-01
Title
  • {{ data }}

var app = angular.module('myApp', ['ngWebSocket'])

.factory('MyData', function ($websocket) {

// Open a WebSocket connection

var dataStream = $websocket('ws://118.145.23.94/rwservice');

var collection = [];

dataStream.onMessage(function (message) {

collection.push(JSON.parse(message.data).data.desp);

});

var methods = {

collection: collection,

get: function () {

dataStream.send(JSON.stringify({action: 'get'}));

}

};

return methods;

})

.controller('customersCtrl', function ($scope, MyData) {

$scope.MyData = MyData;

});

;

 类似资料: