Accessing nested unique key values ​​in firebase

I'm sure this is a trivial question, but can't seem to figure out how to access the id of players in this firebase array. I need to be able to access all player ids, and if the current set on login matches one of the player ids firebase arrays, then these games will loop over the ng-repeat. I know how to accomplish the latter, I just can't figure out how to access the player id inside the unique id; Hope this makes sense. Any help is greatly appreciated, thanks.



(this is part of the code related to my problem)

game.controller('games.controller', ['$scope', '$state', '$stateParams', 'Auth', '$firebaseArray','Fire', function ($scope, $state, $stateParams, auth, $firebaseArray, fire) {

  $ = $firebaseArray(fire.child('games'));
  $scope.view = 'listView';

  $scope.setCurrentGame = function(game) {
    $scope.currentGame = game;

  $scope.createGame = function() {
    if ($scope.format == 'Match Play') {
      $scope.skinAmount = 'DOES NOT APPLY';
      $scope.birdieAmount = 'DOES NOT APPLY';
      name: $scope.gameName,
      host: $,
      date: $scope.gameDate,
      location: {
        course: $scope.courseName,
        address: $scope.courseAddress
      rules: {
        amount: $scope.gameAmount,
        perSkin: $scope.skinAmount,
        perBirdie: $scope.birdieAmount,
        format: $scope.format,
        holes : $scope.holes,
        time: $scope.time

  $scope.addPlayer = function(game) {
      id : $,
      name : $,
      email : $

  // swap DOM structure in games state
  $scope.changeView = function(view){
    $scope.view = view;




source to share

1 answer

You are breaking two general Firebase rules:

  • if the object has a natural unique id, store it with that id as a key
  • do not make lists

I'm guessing # 1 happened because you store players using $firebaseArray.$add()

. Instead of repeating myself, I have listed several questions that address the same problem:

Nesting lists is a common mistake. With players stored in each game, you can never load data for a playlist without also downloading all players for all games. For this reason (and others) it is often better to keep the nested list under its own top level:

           id: "Simplelogin:4"
           name: "Anthony"




All Articles