Sven B Sven B - 1 year ago 57
AngularJS Question

angular hide button if objects object array contains key

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:


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).


You can ng-hide on a $scope.inGame() function that checks $ for the given ID. Like so:

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