I am using AngularFire in my AngularJS project. In the following HTML you can see I am passing the quote item in to the total_votes function in my controller.
<div ng-repeat="quote in quotes" ng-init="total_votes(quote)">
{{quote.name}}
</div>
This is where quotes came from
// get quotes
var ref = firebase.database().ref().child('quotes');
$scope.quotes_obj = $firebaseObject(ref);
$rootScope.quotes = $firebaseArray(ref);
this is what the function looks like
$scope.total_votes = function(itm) {
console.log(itm.votes)
console.log(itm.votes)
console.log(itm.votes[0])
console.log(itm.votes.length)
};
This is what is printed
console.log(itm.votes)
{
"quote": "untitled",
"recorded_by": "-KzFkQYHWKwbAPjIekWz",
"votes": {
"-KzFkQYHWKwbAPjIekWz": "sad",
"-KzLT76T14doKgYbjRc1": "wow"
},
"who": "null",
"$id": "-KzKz7EyCSPkPl0YDvfa",
"$priority": null,
"$$hashKey": "object:15"
}
console.log(itm.votes)
{"-KzFkQYHWKwbAPjIekWz":"sad","-KzLT76T14doKgYbjRc1":"wow"}
console.log(itm.votes[0])
undefined
console.log(itm.votes.length)
undefined
How do I iterate over the votes from quotes? Why is Length Undefined? how come I cant reach the individual items via index like itm.votes[0]?