Conditional reset method "if disable ignore not disable reset" angular

Issue

<div>

     <div>
    <label>Name</label>
    <input type="text" [(ngModel)]="name" [disabled]="editData"
     </div>
  <div>
  <label>address</label>
  <input type="text" [(ngModel)]="address" 
  </div>
</div>

<button (click)=add() >add</button>
<button (click)=edit()>edit</button>
<button (click)=reset()>reset</button>

Note:- On add() both fields should be reset but on edit only address field should be reset by without disturbing previous value in it (ignore disabled field)

ts file

reset(){ this.name=""; this.address="";

}

by doing this all fields are getting reset

Solution

reset(): void{ 
   if(!this.editData) {
     this.name = "";
   }else{
   this.address = this.formvalue.address;
}
}

Answered By – rkamlekar

Answer Checked By – David Marino (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.