https://github.com/shellus/angular-MQTT
获取第三方angular库,引入到项目中。
<scrip{过滤}t src="bower_components/angular/angular.js"></scrip{过滤}t><scrip{过滤}t src="bower_components/angular-mqtt/src/browserMqtt.js"></scrip{过滤}t><scrip{过滤}t src="bower_components/angular-mqtt/src/angular-MQTT.js"></scrip{过滤}t>
var app = angular.module('app', [ 'ngMQTT' ]); app.config(['MQTTProvider',function(MQTTProvider){ MQTTProvider.setHref('ws://cv.endaosi.com:18585'); }]); app.controller('indexCtrl', ['$scope', 'MQTTService', function ($scope, MQTTService) { MQTTService.on('hello', function(data){ alert(data) }); MQTTService.send('hello','word'); MQTTService.send('hello','word1'); MQTTService.send('hello','word2'); }]);
|