I am trying to build a comments system where client sends message to the server and both clients update themself using the Socket.io library.
template:
<div class="list">
<a class="item item-avatar" href="#/app/playlists/{{playlist.id}}" ng-repeat="item in comments">
<img class="round" ng-src="http://178.62.83.248:1337/images/{{item.userImage}}">
<div class="user_checkbox">
<h3>{{item.username}}</h3>
</div>
<p>{{ item.comment }}</p>
</a>
<a class="item item-avatar" href="#/app/playlists/{{playlist.id}}">
<img class="round" ng-src="http://178.62.83.248:1337/images/{{newComment.userImage}}">
<div class="user_checkbox">
<h3>{{newComment}}</h3>
</div>
<p>{{ newComment.comment }}</p>
</a>
</div>
In my controller I have a get request using socket.io:
io.socket.get('http://***.62.83.248:1337/posts/' + shareDataService.getData(), function (data, jwres){
$scope.comments = data.comments;
})
which works fine.I also have a socket update event.
io.socket.on('posts', function(newComment){
$scope.newComment = newComment.data.comments[newComment.data.comments.length-1];
console.log($scope.newComment.comment);
});
when I console log the new data it returns me exactly what I wanted but the scope only updates the client who has send the comment to the server(only client a updates and client b stays the same so I have ruled out any syntex error. anyone has anyidea how i fix this?