elghazal-a
elghazal-a

Reputation: 590

ngShow/ngHide using a function

I have a button that I want to hide when the array $scope.game.players.players contains specific value.

button(ng-click="", ng-hide="ImPlaying()") Play

The function ImPlaying() checks the condition and return a boolean

$scope.ImPlaying = function(){
    $scope.game.players.playerExist($scope.user.socketID, function(exist){
        console.log(exist);
        return exist;
    });
}

exist change value but the button is always shown

But when I replace the function $scope.game.players.playerExist() by its code everything works as expected.

$scope.ImPlaying = function(){
    for (var i = 0; i < $scope.game.players.players.length; i++) {
        if($scope.game.players.players[i]){
            if($scope.game.players.players[i].socketID == $scope.user.socketID){
                return true;
            }
        }
    };
    return false;
}

What's wrong with the first function ?

Upvotes: 0

Views: 85

Answers (1)

Prasad K - Google
Prasad K - Google

Reputation: 2584

You're missing return statement in ImPlaying function

$scope.ImPlaying = function(){
    return $scope.game.players.playerExist($scope.user.socketID, function(exist){
        console.log(exist);
        return exist;
    });
}

Upvotes: 2

Related Questions