0
我有以下控制器火力地堡高内存和CPU使用率
var myApp = angular.module("MyApp", ["firebase"]);
function MyController($scope, $firebase) {
var rootRef = new Firebase("vivid-fire-447.firebaseio.com/products");
// Automatically syncs everywhere in realtime
$scope.products = $firebase(rootRef);
$scope.products.$on('loaded', function(){
var index = $scope.products.$getIndex();
$scope.total = function(){
var total = 0;
index.forEach(function(i){
total += $scope.products.$child(i).price;
});
return total;
};
});
}
和下面的HTML
<div ng-app="MyApp">
<div ng-controller="MyController">
<ul>
<li ng-repeat="product in products | orderByPriority">{{product.code}}</li>
</ul>
<div>Total = {{total()}}</div>
</div>
</div>
的问题是,当我告诉产品铬CPU的总价被在100挂%和内存使用率开始迅速攀升,最终该选项卡挂起。
我注意到使用AngularJS Batarang,总方法被称为连续?
如何以有效的方式获得所有产品的总价格?
我的代码加载速度快,问题就陷入了一个无限循环(你必须改变我的小提琴插值'总()'然后使用Chrome的任务管理器,查看症状),我最好的shot:$ child会以某种方式导致更改事件,并且会角度调用'total()',这会再次触发更改事件,等等。你的代码通过不使用'$ child'解决了这个问题,谢谢!并感谢其他指针。 – Cesar
塞萨尔,这是有道理的,似乎极有可能是罪魁祸首! – Kato