AngularJs Reset Form Fields


AngularJs Reset Form Fields : Sometimes we need to reset form fields in AngularJs. It is very easy to reset form fields in Angularjs . Here in this tutorial we are going to explain how you can reset form fields in AngularJs. You can use our online editor to try & edit the code.


AngularJs Reset Form Fields Example

You can reset form fields in angularjs as below –

Html Part

Html Part Contains the form with two fields email and password which we will reset using the AngularJS.

AngularJs Reset Form Fields Example:

<div ng-app="myApp">  
<div ng-controller="myController">  
<form action="">
<input type="text" name="email" ng-model="email"><br>
<input type="password" name="password" ng-model="password"><br>
<input type="button" value="Reset" ng-click="resetForm()">   <input type="submit" value="Submit" >
<br>
</form>
</div> 

JavaScript Part

Javascript part contains the following code to reset the form fields as below –

AngularJs Reset Form Fields Example:

<div ng-app="myApp">  
<div ng-controller="myController">  
<form action="">
<input type="text" name="email" ng-model="email"><br>
<input type="password" name="password" ng-model="password"><br>
<input type="button" value="Reset" ng-click="resetForm">   <input type="submit" value="Submit" ng-click="">
<br>
</form>
</div> 

Try it »

The above function will reset the two form fields email and passwords. On the same way you can clear more fields if your form has more fields.

If you run the above example it will produce the output something like this –

AngularJs Reset Form Fields


Advertisements

Add Comment

📖 Read More