以下是我的angularJS
代码,socket.io
它仅在我从视图切换时获取值,尽管我希望它会自动更新值。让我知道我在这里做错了什么 -
angular.module("app").controller("DashboardController", function($scope, SessionService) {
$scope.user = SessionService.currentUser;
// Code for realtime notifications
if (SessionService.currentUser._id) {
var socket = io('http://localhost:6868');
socket.emit('get notifications', {user_id: SessionService.currentUser._id});
socket.on('notification data', function(data){
$scope.$apply(function() {
$scope.notificationCount = data.length;
});
});
}
});