嗨,大家好我有一点Angular这个简单的话:
app.controller('FriendsController', ['$scope', 'Page', 'Title', '$http', function($scope, Page, Title, $http) {
$http.get('/friends')
.success(function(data) {
$scope.friends = data.data;
})
socket.on('friendslist', function(resp) {
// Socket was emitted that a user was updated, they are now either Offline or Online
// So find the proper element and update them to the new value
if (resp.verb === "updated") {
for (var i = 0; i < $scope.friends; i++) {
if ($scope.friends[i].id === resp.id) {
$scope.friends[i].online = resp.data.online;
}
}
//var $friendEl = $('i').find('[data-id="1"]').first();
//console.log($friendEl);
//
}
});
}]);
我在发送套接字后很好地将数据传送到客户端,但是如果我console.log(resp)
它返回所需的数据,它似乎没有更新值,但是当我console.log($scope.friends[i])
更新之后仍然会说它是什么初始化的,就像for循环没有找到它并更新它,但我知道它是。任何信息都会非常感谢。
答案 0 :(得分:0)
不应该是forloop中的$ scope.friends.length吗?