我的范围内有属性socketStatus,已更新。视图无法识别更新。
控制器:
var socket = io.connect(localStorage.serverURL);
$scope.socketState = "not connected";
socket.on('connect', function(){
$scope.socketState = "connected";
socket.emit('register', 'clients', function(confirm){
if(confirm)
$scope.socketState = "entered room";
});
});
socket.on('disconnect', function(){
$scope.socketState = "disconnected";
});
视图:
{{socketState}}
虽然已连接套接字且已输入房间,但视图总是显示“未连接”。
答案 0 :(得分:0)
尝试使用
$scope.$apply(function () {
$scope.socketState = "entered room";
});