0

I'm stuck with my mini project, I have a feeling it's something trivial...

I am trying to bind websocket messages to angular datamodel. I don't seem to be able to do that...

Below my controller and a little bit of html to display the data.

    controllers.WebsocketController = mainModule.controller('WebsocketController', function($scope){
    $scope.test = 'test string';
    var socket = new SockJS('/dashboard');
    stompClient = Stomp.over(socket);
    stompClient.connect({}, function(frame) {
        setConnected(true);
        console.log('Connected: ' + frame);
        stompClient.subscribe('/topic/dashboardEntries', function(message){
            $scope.dashboardEntries = message.body;
        });
    });
})

That's what I'm using to display the data:

<div id="dateDiv" class="container" ng-controller="WebsocketController">
    <p id="response"> {{dashboardEntries}} </p>
    <p id="response1"> {{test}} </p>
</div>

I cannot seem to understand why the test data object is displayed and the dashboard entries are not... I debugged my code and I am getting these messages - also I was able to populate that paragraph using jQuery, but data binding does not seem to work...

1 Answer 1

1
$scope.$apply();

did the trick...

Sign up to request clarification or add additional context in comments.

1 Comment

where did you apply

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.