angularjs - 删除在购物车 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>
按钮删除项目不响应
谢谢
解决方案
推荐阅读
- c# - 如何仅使用一个类制作级联下拉列表?
- java - 相邻数组的最小值
- javascript - 使用模拟从玩笑测试中获得覆盖
- python - 从某个文件运行时,readline() 不返回任何内容
- rest - 如何使用 AppRole 从 Vault API 中检索秘密数据?
- python-3.x - Python程序列出所有修改日期的文件夹
- awk - awk 中基于列值的条件转置
- react-native - 如何实施协助用户准确导航到任何地方的特定位置的最短路径
- java - drools.dump.dir 属性不通过api方法转储java版本的drool文件?
- html - PrimeFaces 对话框中的传单地图不正确渲染