Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

I creating simple order system for store. Adding product to cart ,inserting, order, removing cart product is working. After some test i found error and i don't found how to fix this on google.
I have product list, user click product name, and inserting to cart. Cart is array of product where array index is product id.

$scope.addToCart= function (product) {

            if ($scope.cart[product.id] === undefined)  {
                product.count=1;
                $scope.cart[product.id]=product;
            }
            else
            {
                var p=$scope.cart[product.id];
                p.count++;
                $scope.cart[product.id]=p;

            }
    }

When user click add order button i creating object

var order = {
                'cart': $scope.cart
            }

sending this object post and when done i clearing cart array

$scope.cart = [];

I printing this order on order list. When user add product what exist in orders list he changing cart of order, this is only view not database. I now angular bind $scope.cart to order object. How to prevent this? I was tried angular.copy.

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.