marcel
marcel

Reputation: 3272

AngularJS view doesn't get updated

I have the attribute socketStatus in my scope, which is updated. The view doesn't recognize the update.

controller:

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";
});

view:

{{socketState}}     

the view alway shows "not connected" although the socket is connected and the room is entered.

Upvotes: 0

Views: 31

Answers (1)

Narek Mamikonyan
Narek Mamikonyan

Reputation: 4611

try to use

$scope.$apply(function () {
            $scope.socketState = "entered room";
        });

Upvotes: 0

Related Questions