Why product quantity change, When i am push two or more than two time of same product in array












-2















I am having the following problem when I am pushing same product two times in the array then both product quantity showing same. For Example Suppose ABC is my product when I push it into XYZ array with 10 quantity, second-time same product push in XYZ array with quantity 15 then both product quantity showing 15, means last push product quantity replace in all product which is the same name and same id. Here is my code which I have done, please check and rectify my issue.



JS Code



    $scope.XYZ = ;
$scope.addProductInBag = function(prod){
$scope.XYZ.push(prod); //inside of prod productname,quantity,id as well.
}


HTML Code



<a class="btn btn-default" ng-click="addProductInBag(prod)">Push</a>
<div ng-repeat="prd in XYZ">
<div>{{prd.id}}</div>
<div>{{prd.productname}}</div>
<div>{{prd.quantity}}</div>
</div>









share|improve this question

























  • Hi. Please add code showing how you are calling addProductInBag function

    – Nikhil Aggarwal
    Nov 27 '18 at 6:42













  • Try to change the ng-repeat clause as ng-repeat="prd in XYZ track by $index".

    – 31piy
    Nov 27 '18 at 6:44











  • ok used it, but still facing same issue

    – Samadhan Patil
    Nov 27 '18 at 6:50
















-2















I am having the following problem when I am pushing same product two times in the array then both product quantity showing same. For Example Suppose ABC is my product when I push it into XYZ array with 10 quantity, second-time same product push in XYZ array with quantity 15 then both product quantity showing 15, means last push product quantity replace in all product which is the same name and same id. Here is my code which I have done, please check and rectify my issue.



JS Code



    $scope.XYZ = ;
$scope.addProductInBag = function(prod){
$scope.XYZ.push(prod); //inside of prod productname,quantity,id as well.
}


HTML Code



<a class="btn btn-default" ng-click="addProductInBag(prod)">Push</a>
<div ng-repeat="prd in XYZ">
<div>{{prd.id}}</div>
<div>{{prd.productname}}</div>
<div>{{prd.quantity}}</div>
</div>









share|improve this question

























  • Hi. Please add code showing how you are calling addProductInBag function

    – Nikhil Aggarwal
    Nov 27 '18 at 6:42













  • Try to change the ng-repeat clause as ng-repeat="prd in XYZ track by $index".

    – 31piy
    Nov 27 '18 at 6:44











  • ok used it, but still facing same issue

    – Samadhan Patil
    Nov 27 '18 at 6:50














-2












-2








-2


0






I am having the following problem when I am pushing same product two times in the array then both product quantity showing same. For Example Suppose ABC is my product when I push it into XYZ array with 10 quantity, second-time same product push in XYZ array with quantity 15 then both product quantity showing 15, means last push product quantity replace in all product which is the same name and same id. Here is my code which I have done, please check and rectify my issue.



JS Code



    $scope.XYZ = ;
$scope.addProductInBag = function(prod){
$scope.XYZ.push(prod); //inside of prod productname,quantity,id as well.
}


HTML Code



<a class="btn btn-default" ng-click="addProductInBag(prod)">Push</a>
<div ng-repeat="prd in XYZ">
<div>{{prd.id}}</div>
<div>{{prd.productname}}</div>
<div>{{prd.quantity}}</div>
</div>









share|improve this question
















I am having the following problem when I am pushing same product two times in the array then both product quantity showing same. For Example Suppose ABC is my product when I push it into XYZ array with 10 quantity, second-time same product push in XYZ array with quantity 15 then both product quantity showing 15, means last push product quantity replace in all product which is the same name and same id. Here is my code which I have done, please check and rectify my issue.



JS Code



    $scope.XYZ = ;
$scope.addProductInBag = function(prod){
$scope.XYZ.push(prod); //inside of prod productname,quantity,id as well.
}


HTML Code



<a class="btn btn-default" ng-click="addProductInBag(prod)">Push</a>
<div ng-repeat="prd in XYZ">
<div>{{prd.id}}</div>
<div>{{prd.productname}}</div>
<div>{{prd.quantity}}</div>
</div>






angularjs angularjs-scope






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 27 '18 at 6:46







Samadhan Patil

















asked Nov 27 '18 at 6:40









Samadhan PatilSamadhan Patil

105




105













  • Hi. Please add code showing how you are calling addProductInBag function

    – Nikhil Aggarwal
    Nov 27 '18 at 6:42













  • Try to change the ng-repeat clause as ng-repeat="prd in XYZ track by $index".

    – 31piy
    Nov 27 '18 at 6:44











  • ok used it, but still facing same issue

    – Samadhan Patil
    Nov 27 '18 at 6:50



















  • Hi. Please add code showing how you are calling addProductInBag function

    – Nikhil Aggarwal
    Nov 27 '18 at 6:42













  • Try to change the ng-repeat clause as ng-repeat="prd in XYZ track by $index".

    – 31piy
    Nov 27 '18 at 6:44











  • ok used it, but still facing same issue

    – Samadhan Patil
    Nov 27 '18 at 6:50

















Hi. Please add code showing how you are calling addProductInBag function

– Nikhil Aggarwal
Nov 27 '18 at 6:42







Hi. Please add code showing how you are calling addProductInBag function

– Nikhil Aggarwal
Nov 27 '18 at 6:42















Try to change the ng-repeat clause as ng-repeat="prd in XYZ track by $index".

– 31piy
Nov 27 '18 at 6:44





Try to change the ng-repeat clause as ng-repeat="prd in XYZ track by $index".

– 31piy
Nov 27 '18 at 6:44













ok used it, but still facing same issue

– Samadhan Patil
Nov 27 '18 at 6:50





ok used it, but still facing same issue

– Samadhan Patil
Nov 27 '18 at 6:50












1 Answer
1






active

oldest

votes


















1














The below code works fine. Please check this plunker for your given example scenario.



Controller:



  $scope.XYZ = ;
$scope.addProductInBag = function(prod){
var dummy = {
id: 10001 + ($scope.XYZ.length),
productname: 'TEST' + ($scope.XYZ.length + 1),
quantity: 2 + ($scope.XYZ.length)
}
$scope.XYZ.push(dummy);
};





share|improve this answer
























  • Its working, Thank you Immanuel Kirubaharan

    – Samadhan Patil
    Nov 27 '18 at 9:17











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53494082%2fwhy-product-quantity-change-when-i-am-push-two-or-more-than-two-time-of-same-pr%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














The below code works fine. Please check this plunker for your given example scenario.



Controller:



  $scope.XYZ = ;
$scope.addProductInBag = function(prod){
var dummy = {
id: 10001 + ($scope.XYZ.length),
productname: 'TEST' + ($scope.XYZ.length + 1),
quantity: 2 + ($scope.XYZ.length)
}
$scope.XYZ.push(dummy);
};





share|improve this answer
























  • Its working, Thank you Immanuel Kirubaharan

    – Samadhan Patil
    Nov 27 '18 at 9:17
















1














The below code works fine. Please check this plunker for your given example scenario.



Controller:



  $scope.XYZ = ;
$scope.addProductInBag = function(prod){
var dummy = {
id: 10001 + ($scope.XYZ.length),
productname: 'TEST' + ($scope.XYZ.length + 1),
quantity: 2 + ($scope.XYZ.length)
}
$scope.XYZ.push(dummy);
};





share|improve this answer
























  • Its working, Thank you Immanuel Kirubaharan

    – Samadhan Patil
    Nov 27 '18 at 9:17














1












1








1







The below code works fine. Please check this plunker for your given example scenario.



Controller:



  $scope.XYZ = ;
$scope.addProductInBag = function(prod){
var dummy = {
id: 10001 + ($scope.XYZ.length),
productname: 'TEST' + ($scope.XYZ.length + 1),
quantity: 2 + ($scope.XYZ.length)
}
$scope.XYZ.push(dummy);
};





share|improve this answer













The below code works fine. Please check this plunker for your given example scenario.



Controller:



  $scope.XYZ = ;
$scope.addProductInBag = function(prod){
var dummy = {
id: 10001 + ($scope.XYZ.length),
productname: 'TEST' + ($scope.XYZ.length + 1),
quantity: 2 + ($scope.XYZ.length)
}
$scope.XYZ.push(dummy);
};






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 27 '18 at 7:18









Immanuel KirubaharanImmanuel Kirubaharan

1,0811815




1,0811815













  • Its working, Thank you Immanuel Kirubaharan

    – Samadhan Patil
    Nov 27 '18 at 9:17



















  • Its working, Thank you Immanuel Kirubaharan

    – Samadhan Patil
    Nov 27 '18 at 9:17

















Its working, Thank you Immanuel Kirubaharan

– Samadhan Patil
Nov 27 '18 at 9:17





Its working, Thank you Immanuel Kirubaharan

– Samadhan Patil
Nov 27 '18 at 9:17




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53494082%2fwhy-product-quantity-change-when-i-am-push-two-or-more-than-two-time-of-same-pr%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

Calculate evaluation metrics using cross_val_predict sklearn

Insert data from modal to MySQL (multiple modal on website)