I connect to a server through websockets with sockJS. When subscribe messages are retrieving, it does not update the $scope
. I use a service to encapsulate websocket connection. Here is my service function .
serviceMod.service('stompMessageService',function(){
var mz = {msg:'initValue'};
function connect() {
var url='/hello/simplemessages';
var socket = new SockJS(url);
stompClient = Stomp.over(socket);
stompClient.connect('user', 'guest', function(frame) {
stompClient.subscribe("/topic/simplemessagesresponse", function(servermessage) {
console.log('server msg: '+servermessage);
mz.msg=servermessage;
});
});
}
connect();
return mz;
});
My controller
serviceMod.controller('stats', function($scope,stompMessageService) {
$scope.mm=stompMessageService;
});
in html page {{mm.msg}}
. This gives only the first assign value 'initValue' not the server updates.(server response is comming. I tested with console.log().. ). .. Any one can let me know where can be problem