添加订单时我想找到价格的总购物车。 这是我的代码:如何在订购商品时找到小计。 请帮帮我怎么找到这个?
mainCtrl.controller("OrderController",function($scope,function(){
var itemlist={}
$scope.subtotal=function(){
var amount = 0;
for(var i = 0; i < $scope.itemlist.length; i++){
angular.forEach($scope.itemlist[i].itemname, function (){
if($scope.itemlist[i].itemname==MenuItem.itemname){
var product = $scope.itemlist[i];
product.qty=product.qty+1;
amount += (product.itemprice * product.qty);
}
})
console.log("this is cart amount" + amount)
return amount;
}
}
}
$scope.add=function(item){
var MenuItem={"itemid":item.itemid,"itemname":item.itemname,"itemimage":item.itemimage,"qty":1,"itemprice":item.itemprice,"subtotal":subtotal(),"tax":0,"total":$scope.subtotal()}
var exists=false;
angular.forEach($scope.itemlist, function (item) {
if ((item.itemname == MenuItem.itemname)) {
exists=true;
item.qty++;
return false
}
})
if(!exists){
itemlist.push(MenuItem);
growl.success("Your Item added Sucessfully",{title:"Success"});
}
}
})