G.D. Singh G.D. Singh - 11 months ago 46
AngularJS Question

Angular array not updating view

I am implementing a chat module using angularJs, socketIo. (and nodeJS for backend).

In angular there is array attached to scope: $scope.messages.
For a chat client all messages are pushed into this array, and this array is rendered in the view using ng-repeat.

<div class="chat-window">
<div class="chat-message" ng-repeat="message in messages track by $index">{{message}} </div>

However, when i push elements into 'messages' array, it is not getting rendered, unless there is a keypress or mouse event. I have checked and there no keypress or mouse event listeners. The view is somehow now getting updating automatically.

Can someone suggest me the problem?


I think you have push your data using ajax.

jQuery ajax is out of capability of angular, you need to wrap like below, it will tell the $scope.message is going to update and update the view also..

after you push the data try applying...

    $scope.message= data;