[英]Angular 2 change input value on focusout with same value in a row
I am trying to substract input value on focousout by 1. The strange problem is that it does the first time when I enter 100 and click aside(I get in view 99), but the second time I enter 100, it doesn't change although I can see in debug mode that the num property has been changed. 我正在尝试将focousout上的输入值减去1。一个奇怪的问题是,当我第一次输入100并单击旁边时(我进入视图99),它会执行此操作,但是第二次输入100时,它不会更改尽管我可以在调试模式下看到num属性已更改。
For this purpose I am just using one way binding and focusout event. 为此,我仅使用一种方法绑定和聚焦事件。
In html: 在html中:
<input type="text" #numElement [ngModel]="num"
(focusout)="distractByOne(numElement.value)" />
In Component: 在组件中:
distractByOne(val) {
this.num = +val-1;
}
have you tried with .. 你尝试过..
<input type="text" #numElement [ngModel]="num"
(focusout)="distractByOne($event)" />
In Component: 在组件中:
distractByOne(val) {
this.num = +val-1;
}
Hope it helps you ... 希望它可以帮助您...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.