使用angularjs来计算订购商品的总和子总数?

时间:2016-04-07 08:39:30

标签: angularjs

添加订单时我想找到价格的总购物车。 这是我的代码:如何在订购商品时找到小计。 请帮帮我怎么找到这个?

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"});
    }
}
})

0 个答案:

没有答案