2

I want to compare old and new values of ngmodel in ngModelchange function. I tried few solutions from stackoverflow but nothing is working in my case

This is my html code

<input type="text" [(ngModel)]="item.quantity" class="editInput" (ngModelChange)="rowchangcheck($event,item,i)" name="qty">

This is the function

 rowchangcheck(event, item, index) {
   console.log('oldvalue', item.quantity); //here value is getting changed
}

I have tried this but its not working stackoverflow answer

I want to get first value of ngModel before rowchange function and want to compare changed value with old one.How to do that please help

zgue
  • 3,793
  • 9
  • 34
  • 39
Uidev123
  • 73
  • 3
  • 13

1 Answers1

1

I tried a few things like you, and I could only get it to work for the second input - for my first input the old value would always be undefined

The best I can come up with as of now is to add an OldQuantity: plunker

rowchangcheck(oldValue, event, item) {
  console.log('oldValue', item.oldQuantity);
  console.log('newValue', event);
  item.oldQuantity = event;
}
Lasse
  • 131
  • 7