我想在 ngModelchange 函数中比较 ngmodel 的新旧值。我尝试了一些来自 stackoverflow 的解决方案,但在我的案例中没有任何效果
这是我的html代码
<input type="text" [(ngModel)]="item.quantity" class="editInput" (ngModelChange)="rowchangcheck($event,item,i)" name="qty">
这是函数
rowchangcheck(event, item, index) {
console.log('oldvalue', item.quantity); //here value is getting changed
}
这个我试过了,但是不行 stackoverflow answer
我想在 rowchange 函数之前获取 ngModel 的第一个值,并想将更改后的值与旧值进行比较。如何做到这一点请帮忙
最佳答案
我像你一样尝试了一些东西,但我只能让它为第二个输入工作——对于我的第一个输入,旧值总是未定义
目前我能想到的最好办法是添加一个旧数量: plunker
rowchangcheck(oldValue, event, item) {
console.log('oldValue', item.oldQuantity);
console.log('newValue', event);
item.oldQuantity = event;
}
关于javascript - Angular 2 : In ngModelChange function how to compare old and new values of ngModel?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47788877/