嗨,我是angularjs的新手。在我的购物车应用程序中,我有三个文本字段用于选择数量。从服务器加载的所有三个。对于每个产品,我必须设置不同的ng-click方法来更改数量。如果我单击一个增量按钮,则所有三个数量都在变化。请帮帮我
在控制器中:
$scope.increment = function(id) {
if ($scope.count >= 50) { return; }
var cou = $scope.count++;
//id = id+1;
$scope.total=$scope.price*cou;
$scope.total=$scope.total+35;
};
HTML:
<li ng-repeat="orders in ordersList">
<a href="#"><span class="img"><img class="img-thumbnail" src="images/freslogo.jpg" alt="">
</span><span class="product noproduct clearfix"><span class="name"> <b class="doller"><i class="fa fa-rupee"></i>{{orders.price}}</b></span>{{orders.product_name}}
<span class="price">Order ID # {{orders.id}} </span>
<span class="price">- {{orders.created_date}}</span> </a>
<div id="field1"><b>Qty:</b>
<a href="javascript:;" class="spin-up" data-spin="up"><i id="plus" class="ion-plus-circled" ng-click="increment({{orders.id}});"></i></a>
<input type="text" id="1" value="{{count}}" class="field">
<a href="javascript:;" class="spin-down" data-spin="down"><i class="ion-minus-circled" ng-click="decrement();"></i></a>
</div>
</li>
答案 0 :(得分:0)
试试这个:
$scope.increment = function(orders) {
if (orders.count >= 50) { return; }
var cou = orders.count++;
//id = id+1;
$scope.total=$scope.price*cou;
$scope.total=$scope.total+35;
};
正如您在单个订单中使用count而在控制器部分中,您正在范围级别处理它。对decrement
答案 1 :(得分:0)
$scope.increment = function(order) {
if (order.count >= 50) { return; }
var cou = ++order.count;
//id = id+1;
order.total = order.price*cou;
order.total = order.total+35;
};