Background:
When a delivery is created, an entry will be created under:
1- DELIVERIES->COMPANY->FIREBASEGENERATEDID->DELIVERY DETAILS
To allow users to track their purchases, they will have the delivery company and the unique ID of the delivery added to their profile.
2- USERS->DELIVERYTRACKING->COMPANY(delivery)->FIREBASEGENERATEDID(generated from deliveries above): TRUE
I am able to utilise Firebase.util.intersection to return an array of Firebase references, based on the use case above. However, when bound to a variable in $scope, I am unable to access the specific keys of the child object although I can display the lot to the view.
I've constructed a detailed JSFiddle which should explain the problem much more eloquently that I can by typing.
JSFiddle Link: http://jsfiddle.net/rwk1/8po8t35q/9/
SO required code:
<body ng-app="testApp" ng-controller="TestCtrl">
<div data-ng-repeat="tDelivery in trackedDelivery | orderByPriority">
<div class="profile-cards">
<p>{{tDelivery}}</p>
</div>
</div>
<br/><br/>
<h5>Question: How do I access the individual delivery details i.e. status?</h5>
</body>
'use strict';
var app = angular.module('testApp', [
'firebase'
]);
Controller:
app.controller('TestCtrl', function($scope, $firebase){
var fb = new Firebase('https://so0001.firebaseio.com');
var trackingRef = fb.child('users/Cara/deliveryTracking');
var trackingFb = $firebase(trackingRef);
trackingFb.$on('loaded', function(){
console.log(trackingFb.$getIndex());
});
var trackedDeliveryRefArray = [];
(function(){
trackingFb.$on('loaded', function(){
//console.log(trackingFb.$getIndex());
angular.forEach($firebase(trackingRef ).$getIndex(), function (k,v){
var trackedDeliveryRef = new Firebase.util.intersection(fb.child('users/Cara/deliveryTracking/' + k ),
fb.child('deliveries' + '/' + k ));
trackedDeliveryRefArray.push($firebase(trackedDeliveryRef));
});
});
})();
$scope.trackedDelivery = trackedDeliveryRefArray;
});
Result:
{"-randomFBKey1":{"company1":true,"name":"name value 1","status":"delivery 1 status"}}
{"-randomFBKey3":{"company2":true,"name":"delivery 3","status":"delivery 3 status"}}
Question: How do I access the individual delivery details i.e. status?
Structure: