Why product quantity change, When i am push two or more than two time of same product in array
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
add a comment |
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
Hi. Please add code showing how you are callingaddProductInBag
function
– Nikhil Aggarwal
Nov 27 '18 at 6:42
Try to change theng-repeat
clause asng-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
add a comment |
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
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
angularjs angularjs-scope
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 callingaddProductInBag
function
– Nikhil Aggarwal
Nov 27 '18 at 6:42
Try to change theng-repeat
clause asng-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
add a comment |
Hi. Please add code showing how you are callingaddProductInBag
function
– Nikhil Aggarwal
Nov 27 '18 at 6:42
Try to change theng-repeat
clause asng-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
add a comment |
1 Answer
1
active
oldest
votes
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);
};
Its working, Thank you Immanuel Kirubaharan
– Samadhan Patil
Nov 27 '18 at 9:17
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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);
};
Its working, Thank you Immanuel Kirubaharan
– Samadhan Patil
Nov 27 '18 at 9:17
add a comment |
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);
};
Its working, Thank you Immanuel Kirubaharan
– Samadhan Patil
Nov 27 '18 at 9:17
add a comment |
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);
};
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);
};
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 asng-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