【发布时间】:2014-10-14 14:08:45
【问题描述】:
以下是我的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;
});
});
}
});
【问题讨论】:
-
如果您需要任何其他详细信息,请告诉我
标签: javascript node.js angularjs socket.io mean.io