0

Lets say there is an object(game) that has an array with objects(players) and if the player array has a certain value(_id) that equals the current value I want to hide a button(join).

game object:

    {
        "_id":"123459595",
        "players":[
            {
            "_id":"some_id",
            "name":"some_username"
            }
        ]
    }

I know I can hide the button like:

<button ng-hide="playerJoined">Join game</button>

Where playerJoined is a statement that checks if the players is in the array. I have acces to the current player value from the variable currentPlayer that is available from the $rootScope.

How should I check if the currentPlayer exists as a value in the array with players?

Fiddle of example (without the right check).

4
  • Do you have a plunker for this? Commented Jun 8, 2016 at 20:01
  • @jsmtslch added a fiddle Commented Jun 8, 2016 at 20:10
  • jsfiddle.net/Lvc0u55v/5155 <br> So I added condition in your ng-hide. Is this what you want to do? Commented Jun 8, 2016 at 20:17
  • @jsmtslch no i want to check if the curretnPlayer value is in the player array Commented Jun 8, 2016 at 20:19

1 Answer 1

2

You can ng-hide on a $scope.inGame() function that checks $scope.game.players for the given ID. Like so: http://jsfiddle.net/mxhy0sdd/

P.S. Don't use $rootScope to share data between controllers :P I fixed this as well

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.