我正在开发具有离子,角度的电子商务购物应用程序我是初学者我的购物车工作正常,但我想添加一个显示数量无法做到的徽章。
这是我的购物车控制器
.controller('cartCtrl', function($scope,$rootScope,sharedCartService,$ionicPopup,$state,$http) {
$scope.cart=sharedCartService.cart_item; // Loads users cart
$scope.get_qty = function() {
$scope.total_qty=0;
$scope.total_amount=0;
}
//onload event-- to set the values
$scope.$on('$stateChangeSuccess', function () {
$scope.cart=sharedCartService.cart;
$scope.total_qty=sharedCartService.total_qty;
$scope.total_amount=sharedCartService.total_amount;
});
//remove function
$scope.removeFromCart=function(c_id){
$scope.cart.drop(c_id);
$scope.total_qty=sharedCartService.total_qty;
$scope.total_amount=sharedCartService.total_amount;
};
$scope.inc=function(c_id){
$scope.cart.increment(c_id);
$scope.total_qty=sharedCartService.total_qty;
$scope.total_amount=sharedCartService.total_amount;
};
$scope.dec=function(c_id){
$scope.cart.decrement(c_id);
$scope.total_qty=sharedCartService.total_qty;
$scope.total_amount=sharedCartService.total_amount;
};
$scope.checkout=function(){
if($scope.total_amount>0){
$state.go('checkOut');
}
else{
var alertPopup = $ionicPopup.alert({
title: 'No item in your Cart',
template: 'Please add Some Items!'
});
}
};
用户将产品添加到购物车的菜单
<ion-list ng-repeat="item in menu_items">
<ion-item class="item-thumbnail-left" >
<img ng-src="{{'img/'+ item.p_image_id +'.jpg'}}" ng-click="showProductInfo(item.p_id,item.p_description,item.p_image_id,item.p_name,item.p_price)" >
<p style="position:absolute;right:10px;">
<a ng-click="addToCart(item.p_id,item.p_image_id,item.p_name,item.p_price)" class="button button-balanced button-clear icon ion-android-cart"> </a>
</p>
<h2 ng-click="showProductInfo(item.p_id,item.p_description,item.p_image_id,item.p_name,item.p_price)" > {{item.p_name}} </h2>
<p ng-click="showProductInfo(item.p_id,item.p_description,item.p_image_id,item.p_name,item.p_price)">Price: ₹ {{item.p_price}}</p>
</ion-item>
</ion-list>