首页 > 解决方案 > 删除在购物车 codeigniter 和 angularjs 中不起作用的项目

问题描述

我有如下问题,我在后端使用 codeigniter 创建,在前端使用 angular 计算,我的问题是删除 itam 不起作用,并且函数 setTotal 不起作用..

详细代码,像这样

<tr ng-repeat = "cart in carts.data">
  <td>{{cart.product_name}}</td>
  <td>{{cart.product_price}}</td>
  <td>{{cart.product_quantity}}</td>
  <td>{{cart.product_quantity * cart.product_price | rupiah}}</td>
  <td><button type="button" name="remove_product" class="btn btn-danger btn-xs" ng-click="removeItem(cart.product_id)"><i class="fa fa-close"></i></button></td>
</tr>

<script type="text/javascript">
  var app = angular.module('api', []);

  app.controller('harga', function ($scope, $http){

    $scope.carts = []; 
    $scope.fetchCart = function(){
      $http({
        method: 'GET',
        url: '<?php echo base_url(); ?>shop/fetch_cart'
      }).then(function (data){
        $scope.carts = data;
      },function (error){
        alert('salah');
      });
    };
    
    $scope.setTotals = function(){
      var total = 0;
      for(var count = 0; count < $scope.carts.length; count++){
        var item = $scope.carts[count];
        total = total + (item.product_quantity * item.product_price);
      }
      return total;
    };

    $scope.removeItem = function(product_id){
      $http({
        method:"POST",
        url:"<?php echo base_url(); ?>shop/remove_item",
        data:product_id
      }).then(function(data){
        $scope.fetchCart();
      });
    };

  })

</script>

按钮删除项目不响应

谢谢

标签: angularjscodeignitershopping-cart

解决方案


推荐阅读