admin管理员组文章数量:1355542
I am facing a strange issue. I have two similar InputElement in my HTML form. I bind/assign the values to both of them in similar way. However, when I update the binding variable during the execution of the program, one of them gets updated and visible on screen while other does not. I tried changing the bindings, using ngModel but result is the same, Can't figure out what am I doing wrong.
Below is the declaration of InputElement which gets updated correctly.
<input type="number" #reference class="height-20 counter-container" id="speedId" prevValue="0.0" value="{{speed}}">
The below declaration of Input which does not get updated properly.
<input type="number" id="presettype" prevValue="0" #preset class="preset-input" value="{{preset}}" />
I update these both in similar way in the .ts file.
this.speed = value1; this.preset = value2;
But speed gets updated and shown on UI properly, while preset field remains empty.
What could be the possible fix?
I am facing a strange issue. I have two similar InputElement in my HTML form. I bind/assign the values to both of them in similar way. However, when I update the binding variable during the execution of the program, one of them gets updated and visible on screen while other does not. I tried changing the bindings, using ngModel but result is the same, Can't figure out what am I doing wrong.
Below is the declaration of InputElement which gets updated correctly.
<input type="number" #reference class="height-20 counter-container" id="speedId" prevValue="0.0" value="{{speed}}">
The below declaration of Input which does not get updated properly.
<input type="number" id="presettype" prevValue="0" #preset class="preset-input" value="{{preset}}" />
I update these both in similar way in the .ts file.
this.speed = value1; this.preset = value2;
But speed gets updated and shown on UI properly, while preset field remains empty.
What could be the possible fix?
Share Improve this question asked Mar 31 at 10:53 Himanshu1983Himanshu1983 916 bronze badges 1 |2 Answers
Reset to default 2Resolved the problem. I was using the same variable name for template variable and local variable. This was causing the above problem. Once I changed the name of my local variable, it started working.
Given that you are using Interpolation with value attribute: When you use {{ speed }}
inside the value attribute, Angular will interpolate the value into the input, but it does not establish a two-way binding. This means that the input field will display the value of speed when it is initialized, but it won't update the value of speed when the user modifies the input.
I know you said you tried using ngModel but was it exactly as follows?
<input type="number" [(ngModel)]="speed" id="speedId" class="height-20 counter-container">
<input type="number" [(ngModel)]="preset" id="presettype" class="preset-input">
本文标签: angularInputElement not updating with valueStack Overflow
版权声明:本文标题:angular - InputElement not updating with value - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743952986a2567629.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
<input type="number" id="presettype" [prevValue]="0" #preset class="preset-input" [value]="preset" />
– Edo2610 Commented Mar 31 at 12:59