ngShow / ngHide使用函数

时间:2014-09-11 17:30:14

标签: javascript angularjs

当数组$scope.game.players.players包含特定值时,我想隐藏一个按钮。

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

函数ImPlaying()检查条件并返回布尔值

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

exist更改值但按钮始终显示

但是当我用代码替换函数$scope.game.players.playerExist()时,一切都按预期工作。

$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;
}

第一个功能有什么问题?

1 个答案:

答案 0 :(得分:2)

您在ImPlaying函数

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