Only increment one item inside ngFor (Angular 2)


#1

constructor(public navCtrl: NavController,
public navParams: NavParams,
public apiserviceprovider: ApiServiceProvider,
public platform: Platform) {
platform.ready().then(()=>{
platform.registerBackButtonAction(()=>this.goBack());
});
this.session_id = localStorage.getItem(‘session_id_val’);
this.category = navParams.get(‘category_id’);

this.apiserviceprovider.loadproduct(this.category)
.then(data => {
this.productdetails = data;

});

this.qty = 1;

}

// increment product qty
incrementQty(item, data) {
console.log(this.qty+1);
this.qty += 1;
}

// decrement product qty
decrementQty(item, data) {
if(this.qty-1 < 1 ){
this.qty = 1
console.log(‘1->’+this.qty);
}else{
this.qty -= 1;
console.log(‘2->’+this.qty);
}
}
public goBack() {
this.navCtrl.setRoot(HomePage)
}

}

when am clicking increment all the products value is change at a time. what am missed out this code


Increment and decrements item quantity based on id
#2

Please edit your post and use the </> button above the post input field to format your code or error message or wrap it in ``` (“code fences”) manually. This will make sure your text is readable and if it recognizes the programming language it also automatically adds code syntax highlighting. Thanks.

And do you have a question or did you only want to show us your code?


#5

You have only one qty property that is shared by all items. You need to move that into each item itself.


#6

am not getting can u explain clearly.


#7