[英]How to detect change in input using Angular8
i have edit and close button in same row, if there is any edit made to the input field then it must show an alert message, if no change is made it must retain its old value.我在同一行有编辑和关闭按钮,如果对输入字段进行了任何编辑,那么它必须显示一条警报消息,如果没有进行更改,它必须保留其旧值。 My issue here is, i click on edit and do some change to input, when i click on close, i am able to retain new value, but when i click on close, it must revert to old value
我的问题是,我点击编辑并对输入进行一些更改,当我点击关闭时,我可以保留新值,但是当我点击关闭时,它必须恢复为旧值
TS: TS:
public onEditEvent(event) {
this.editCommitment = event;
}
public onCloseEvent(event){
if(event.policyCT == this.editCommitment.policyCT && event.quotes == this.editCommitment.quotes && event.writtenPremium == this.editCommitment.writtenPremium) {
event.writtenPremium = this.editCommitment.writtenPremium;
event.policyCT = this.editCommitment.policyCT;
event.quotes = this.editCommitment.quotes
this.editableRow = 0;
} else {
alert('change')
}
}
By default ng-model will update the model.默认情况下 ng-model 将更新模型。 You need to maintain old value manually when user clicks on edit button.
当用户单击编辑按钮时,您需要手动维护旧值。 Like below:-
如下图:-
selectedRow: any;
public onEditEvent(event) {
this.selectedRow = { ...event };
this.editCommitment = event;
}
Apply that when user click on close button.当用户单击关闭按钮时应用它。
public onCloseEvent(event) {
event.writtenPremium = this.selectedRow.writtenPremium;
event.policyCT = this.selectedRow.policyCT;
event.quotes = this.selectedRow.quotes;
this.editableRow = 0;
}
And on Save click you dont have to do anything as model is already updated.在保存单击时,您无需执行任何操作,因为模型已经更新。
Working Demo:- https://stackblitz.com/edit/angular-turxyo?file=src%2Fapp%2Fapp.component.ts工作演示:- https://stackblitz.com/edit/angular-turxyo?file=src%2Fapp%2Fapp.component.ts
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.