0

I want to create an AngularJS site that updates its information via websockets from the server. The server will emit a new chunk of information every second.

This is the code I have:

myApp.controller('mainController', function($scope) {
  var connection = new WebSocket("ws:localhost:4080/", ['soap', 'xmpp']);
  $scope.value= "null";
  connection.onopen = function () {
    connection.onmessage = function (e) {
      $scope.value = e.data;
    };
  };
};
1
  • So what is the question? What is not working? Commented Mar 18, 2016 at 10:00

1 Answer 1

1

Wrap the $scope.value = e.data; call into $scope.$apply function to propagate the data into view.

$scope.$apply(function() {
    $scope.value = e.data;
});
Sign up to request clarification or add additional context in comments.

Comments

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.