i'm trying to build a very simple chat with express.js, socket.io and angular. it works. the only problem that i have is when the socket message event is fired it isn't synchronizing and rendering it onto the page.
var socket = io.connect('http://localhost:8080');
angular.module('chat',[]).controller('chatController',['$scope','$apply',function($scope,$apply){
chat = $scope;
chat.messages = [];
socket.on('messages',function(data){
chat.$apply(function(){
chat.messages.push(data);
});
});
}])
i know i should use $apply somehow but it gives me an error of unknow provider.
what is the correct way for implementing $apply
No need to pass $apply as a dependency,
Try this
angular.module('chat',[]).controller('chatController',['$scope',function($scope){
$scope.messages = [];
socket.on('messages',function(data){
$scope.$apply(function(){
$scope.messages.push(data);
});
});
}])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With