Firebase $ id from the second level object

So, I have it, for example, in firebase

clients {
   //clients with unique keys {
       invoices: {
         // Invoices with unique Keys
       }
   }
}

I am returning all this with a single ref:

.controller('singleClientController', function($scope, $firebaseObject, fbUrl, $routeParams) {

    var id = $routeParams.id;

    var singleRef = new Firebase(fbUrl+'/clients/'+id);
    var client = this;

    client.details = $firebaseObject(singleRef);

})

so in my html i am trying to return $idfor client and invoice. I can get no problems from the client {{client.details.$id}}, but when I try to do the same with the account ID {{invoice.$id}}, I get nothing.

Invoices are displayed through foreach as follows:

<tr ng-repeat="invoice in client.details.invoices">
     <td>
         <a href="#/invoices/details/{{invoice.$id}}/{{client.details.$id}}">
            {{invoice.settings.number}}
         </a>
     </td>
     ...
</tr>

Is it because invoices are inside the customer? If so, how would you return the identifier for the invoices? It drives me crazy! Please, help!

For a better understanding of my firebase settings, here is a screenshot of what I'm talking about.

enter image description here

+4
source share
1

tl; dr - Firebase .

JSBin

, .

{
   "clients": {
      "1": {
         "name": "Alison",
         "invoices": {
            "0001": {
              "amount": 500
              "paid": true
            }
         }
      }
   }
}

, - . Firebase. Firebase node.

, , /clients/1, , . , -.

, .

{
   "clients": {
      "1": {
        "name": "Alison"
      }
   },
   "clientInvoices": {
     "1": {
        "0001": {
          "amount": 500
          "paid": true
        }
     }
   }
}

.

1. . , , .push().

, - , . -.

ng-repeat .

$firebaseObject $firebaseArray -. factory, - .

.factory('invoices', function(fbUrl, $firebaseArray) {
   return function(clientId) {
      var ref = new Firebase(fbUrl).child('clientInvoices').child(clientId);
      return $firebaseArray(ref);
   }
})

// While we're at it, lets create a helper factory for retrieving a
// client by their id
.factory('clients', function(fbUrl, $firebaseObject) {
    return function(clientId) {
       var ref = new Firebase(fbUrl).child('clients').child(clientId);
       return $firebaseObject(ref);
    }
})

$routeParams.id :

.controller('singleClientController', function($scope, $routeParams, invoices, clients) {

    $scope.client = clients($routeParams.id);
    $scope.clientInvoices = invoices($routeParams.id);

})

- :

<tr ng-repeat="invoice in clientInvoices">
     <td>
         <a href="#/invoices/details/{{invoice.$id}}/{{client.$id}}">
            {{invoice.settings.number}}
         </a>
     </td>
     ...
</tr>
+8

All Articles