Rohit Nair Rohit Nair - 5 months ago 12
jQuery Question

How to reset the angular js calculated field

I have a form where, the values of two fields are calculated using AngularJS Binding. And, I'm also using jquery Reset() method to reset my form.

When using the jquery reset the 'Model' values becomes null; but, the calculated field still remains.

When I manually change the the 'Model' values to '0', the calculated values change.

I tried to change the values of the 'Model' via JS to '0'. But, still the calculated values do not change.

Code Snippet

html form

<form id="form1">
<div ng-app="">
<input type="text" ng-model="Parmale" required/>
<input type="text" ng-model="Parfemale" required/>
<input type="text" value="{{(Parmale-0)+(Parfemale-0)}}/>
</div>
</form>


JS

document.getElementById("form1").reset();


Can someone please guide me through?

If this question seems ridiculous, please bear with me! I'm just a student trying to learn.

Answer

Change following line

<input type="text" value="{{(Parmale-0)+(Parfemale-0)}} />

to

<input type="text" ng-model="Parmale+Parfemale" />

and since you are doing mathematical operation i would recommend use input type number, etc. appropriate to your requirement.

Regards.