I am having trouble accessing the data loaded from firebase using the .$on method in AngularFire 0.5.0
In the callback when I log out the contents of the scope the d
Based on Kato's answer here I have been able to solve this.
I was unaware the loaded event passed the raw data of the loaded asset, it is undocumented in the AngularFire docs.
It doesn't explain the odd behaviour I was having with console.log but it does solve the problem.
.controller('AssetDetailCtrl',
['$scope', '$firebase', 'FBURL',
function($scope, $firebase, FBURL) {
var refAsset = new Firebase(FBURL + '/assets/' + $scope.assetId);
$scope.asset = $firebase(refAsset);
// when data is loaded check validity of the route
$scope.asset.$on('loaded', function(value) {
console.log(value); // data loaded from Firebase
console.log(value.name); // subset of the returned value
});
}])
Just for my own sake and others out there that may be having the same issue as i did, stumbling upon this question googling for the answer. My problem was that sometimes i was getting undefined
as the value from the callback of $on('loaded')
.
The way i solved it in the end was to use that event as a way of knowing when i could call the resource.$getIndex()
, and the use the indexes returned from that to loop through the content and possibly store that in a new array to access the raw data.