I've been struggling with the proper implementation of this, I thought I had it but based on the example I am doing it wrong. How do you use this factory in a controller? What is the intended result?
The example:
app.factory("ListWithTotal", ["$FirebaseArray", "$firebase", function($FirebaseArray, $firebase) {
// create a new factory based on $FirebaseArray
var TotalFactory = $FirebaseArray.$extendFactory({
getTotal: function() {
var total = 0;
// the array data is located in this.$list
angular.forEach(this.$list, function(rec) {
total += rec.amount;
});
return total;
}
});
return function(listRef) {
// override the factory used by $firebase
**// why do listRef and ref not match here?
//where does listRef or ref come from**
var sync = $firebase(ref, {arrayFactory: TotalFactory});
return sync.$asArray(); // this will be an instance of TotalFactory
}
}]);
I've been able to use a version of extending factories that doesn't include the return of a reference to a new firebase. For example: A todo list that keeps count: http://plnkr.co/edit/iAGvPHFWn2GSPGzBRpKh?p=preview
listRef, orref. Not one and the other. - user2943490