Search code examples
angularangular2-routingangular2-templateangular2-formsangular2-services

How to clear all my input fields in Angular2


Html

Description
<textarea type="text" #refrence class="form-control" id="description" pattern="^[a-zA-Z0-9/. ]*$" required minlength="30" maxlength="250"  [(ngModel)]="model.description" name="description" #description="ngModel"></textarea>

amount

<input type="text" id="myInput" #refrence #amountInput="ngModel"class="form-control" id="amount"  required minlength="2" maxlength="10" "model.amountInput" name="amount">

customer name

<input type="text" #refrence placeholder="Customer" class="form-control" id="customer"pattern="^[a-zA-Z/. ]*$" required minlength="5" maxlength="25" name="customer" #customer="ngModel">


 <span style="float: right"> 
          <a (click)="refrence.value=''">
                          <i class="fa fa-clean-o" style="font-size:36px"></i>
           </a>
 </span>

Here i have add my html code.in anchor tag i have mentioned (click)="refrence.value=''" and in input fields i have declared #refrence to clear that data . it clears only one input so please tell how to clear all my input fields by clicking clean anchor tag.


Solution

  • If you are not using the reactive form you have to do it in the same way either if you are using a form then you can use form method to clear like

    this.form.reset()
    

    More about forms read out here