SoFunction
Updated on 2025-04-12

angularjs implements simple shopping cart function

The examples in this article share with you the specific code of angularjs to implement the shopping cart function for your reference. The specific content is as follows

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
  <style>
    *{
      margin: 0;
      padding: 0;
      margin-left: 10px;
    }
    li{
      list-style: none;
    }
    .add,.reduce{
      display: inline-block;
      width: 20px;
      height: 20px;
      border: 1px solid #000;
      text-align: center;
    }
    .line{
      border-bottom: 1px solid #000;
    }
  </style>
  <script src="angular-1.5.5/"></script>
  <script>
    var myapp=("myapp",[]);
    ("myCtrl",function($scope){
      $=[
        {
          "shopName":"Fun Art Workshop",
          "checked":false,
          "goods":[
            {
              "goodsName":"Pure handmade wooden clock exquisite furniture decoration ornaments",
              "pic":"images/cart_01.jpg",
              "price":150.00,
              "number":1,
              "checked":false
            },
            {
              "goodsName":"Wooden Bluetooth speakers, free shipping, solid wood furniture decoration ornaments",
              "pic":"images/cart_02.jpg",
              "price":119.00,
              "number":2,
              "checked":true
            },
            {
              "goodsName":"Decorative wood carving, unique and interesting design furniture decoration ornaments",
              "pic":"images/cart_03.jpg",
              "price":120.00,
              "number":0,
              "checked":false
            }
          ]
        },
        {
          "shopName":"Nei Street Paper Art",
          "checked":false,
          "goods":[
            {
              "goodsName":"Pure handmade wooden clock exquisite furniture decoration ornaments",
              "pic":"images/cart_04.jpg",
              "price":89.00,
              "number":2,
              "checked":true
            },
            {
              "goodsName":"Wooden Bluetooth speakers, free shipping, solid wood furniture decoration ornaments",
              "pic":"images/cart_05.jpg",
              "price":189.00,
              "number":1,
              "checked":false
            }
          ]
        },
        {
          "shopName":"I go to paper",
          "checked":true,
          "goods":[
            {
              "goodsName":"Pure handmade wooden clock exquisite furniture decoration ornaments",
              "pic":"images/cart_06.jpg",
              "price":289.00,
              "number":3,
              "checked":true
            }
          ]
        }

      ];
      //Click the Add or Subtract button to add or subtract the quantity; click the Delete button to delete the product      $=function(goods){
        --;
        if (<=0) =0;
        $();
      };
      $=function(kind){
        ++;
        $();
      };
      $=function(item,index){
        (index,1)
      };
      /*Total amount calculation*/
      $=function(){
        var total=0;
        for(var i=0;i<$;i++){
          for(var j=0;j<$[i].;j++){
            if($[i].goods[j].checked){
              total+=$[i].goods[j].price*$[i].goods[j].number;
            }
          }
        }
        return total;
      };
      /*Shop selection*/
      $=function(item){
        if(==true){
          for(var i=0;i<;i++){
            [i].checked=true
          }
        }else {
          for(var i=0;i<;i++){
            [i].checked=false;
          }
        }
      };
      /*Select all*/
      $=function(){
        if($){
          for(var i=0;i<$;i++){
            $[i].checked=true;
            for(var j=0;j<$[i].;j++){
              $[i].goods[j].checked=true;
            }
          }
        }else {
          for(var i=0;i<$;i++){
            $[i].checked=false;
            for(var j=0;j<$[i].;j++){
              $[i].goods[j].checked=false;
            }
          }
        }
      };
    })
  </script>
</head>
<body ng-app="myapp" ng-controller="myCtrl">
<div><input type="checkbox" ng-model="allCheck" ng-click="allChecked()">lump sum:<span>{{ totalMoney() | currency:"¥"}}</span></div>
<div ng-repeat="item in cart" class="line">
  <div><input type="checkbox" ng-model="" ng-click="shopChecked(item)"><span>{{}}</span></div>
  <ul>
    <li ng-repeat="kind in ">
      <input type="checkbox" ng-model=""><span>{{}}</span>
      <p>{{}}</p>
      <p><span class="add" ng-click="add(kind)">+</span>{{}}<span class="reduce" ng-click="reduce(kind)">-</span></p>
      <p ng-click="delete(item,$index)">delete</p>
    </li>
  </ul>
</div>

</body>
</html>

The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.