我一直在努力适当地实现这个,我以为我有它,但基于这个例子,我做错了。你如何在控制器中使用这个工厂?预期的结果是什么?了解AngularFire扩展FirebaseArray示例?
的例子:
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
}
}]);
我已经能够使用一个版本扩展的工厂不包括引用到一个新的火力点的回报。例如:一个待办事项清单保持计数:http://plnkr.co/edit/iAGvPHFWn2GSPGzBRpKh?p=preview
这是一个错字。它们都应该是'listRef'或'ref'。没有一个和另一个。 – user2943490 2014-12-08 05:37:16