0

I'm working on an application that requires a chat feature. It seems to work apart from the fact that in order for the chat message list to update, I have to perform an action for example type in the search box or click the "Send" button. The Chat receives messages through a websocket service (the service works fine). So it seems that the directory's DOM doesn't get updated before it is interacted with. I have also tried putting everything in without a directory and it still didn't work right.

I couldn't replicate this issue on JSFiddle (I couldn't include all of the code, but the base required for this to work is there).

I'm looking for ideas as to why this could be happening. Could this be an issue with event scopes? There are also WebsocketManagerService, P2PManagerService and ConnectionManagerService (this connects WS/P2P services) but I don't think it's relevant.

Sending a chat message:

EventManagerService.emit('chat message', 'some message');

Receiving a chat message:

EventManagerService.on(EventManagerService.EVENTS.RECEIVED_CHAT_MESSAGE, function (data) {
    $scope.chatMessages.push({user: 'Client', message: data});
});

http://jsfiddle.net/Iber/6qkdnv3w/

1 Answer 1

2

I believe your model isn't updating.

Try doing this:

EventManagerService.on(EventManagerService.EVENTS.RECEIVED_CHAT_MESSAGE,      function (data) {
$scope.chatMessages.push({user: 'Client', message: data});
if (!$scope.$$phase) $scope.$apply()
});

There's probably a better solution but that would involve redoing a lot of your current code.

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

2 Comments

Brilliant! It worked! What is the cause of the issue? Why isn't it updating automatically?
All I needed was $scope.$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.