0

I have my below code that uses socket.io to get tweets from my back-end. I'm using ntwitter and am opening up a stream. I'm trying to get the tweets into a queue so that I can have them float across the screen at different time intervals, but the socket never stops getting tweets so my queue isn't accessible form my front-end in angular. I do successfully pull the tweets, because I console.log them, I just can't have them show up on the front-end.

socket.on('tweet', function(data){
  $scope.tweetObject = {
    "user": data.user,
    "text": data.text
  }
  $scope.queue.enqueue(tweetObject);
  $scope.tweet = $scope.queue.dequeue();
  console.log($scope.tweet);
});

my html front-end

<div ng-controller="mainSpaceController">
  <div class="tweet" ng-repeat="x in tweetObject">
    <p> in the field</p>
      {{x.user}}
      {{x.text}}

  </div>

</div>
Rafa
  • 3,219
  • 4
  • 38
  • 70

1 Answers1

0

Possibly you need to add response.end() in the end of the response handler on your nodejs backend.

And don't forget to invoke $scope.$apply() after updating your scope with new data to force a digest cycle. Your iteration will be l

Update: In your example tweetObject is not an array it's just a plain object. So you're iterating over its properties, see more here.

The updated code:

<div ng-controller="mainSpaceController">
    <div class="tweet" ng-repeat="(user, text) in tweetObject">
        <p> in the field</p>
        {{user}}
        {{text}}
    </div>
</div>
Dmytro Hutsuliak
  • 1,741
  • 4
  • 21
  • 37