bower install --save ng-stomp
npm install --save ng-stomp
<script src="/bower_components/sockjs/sockjs.min.js"></script>
<script src="/bower_components/stomp-websocket/lib/stomp.min.js"></script>
<script src="/bower_components/stompie/stompie.min.js"></script>
angular.module('yourApp', ['ngStomp']);
Inject it in your controller:
angular
.module('app')
.controller('Ctrl', ['$stomp', '$scope', function ($stomp, $scope) {
// ...
}
Use and subscribe:
// redirect debug
$stomp.setDebug(function (args) {
document.getElementById('log').value += args + '\n';
});
$stomp
.connect('/endpoint', connectHeaders)
// frame = CONNECTED headers
.then(function (frame) {
var subscription = $stomp.subscribe('/dest', function (payload, headers, res) {
$scope.payload = payload;
}, {
"headers": "are awesome"
});
// Unsubscribe
subscription.unsubscribe();
// Send message
$stomp.send('/dest', {
message: 'body'
}, {
priority: 9,
custom: 42 //Custom Headers
});
// Disconnect
$stomp.disconnect(function () {
});
});