Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

253
Vistas
How do we give input type as Reset and a Click event on Reset

I have a Reset button with input type = reset. On click of the Reset button, I need all fields to clear first and then I have to execute a method. So I am using a click event but not able to execute both with type reset.

<button type="reset">Reset</button>                          // Line 1
<button (click)="resetView()" type="button">Reset</button>  // Line 2
resetView(){
  // Some method
}

The first line is enabling only reset of fields. The second line is only hitting the resetView() method without clearing out the fields. How do I include both the reset and resetView() method

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

There are 3 ways comes to my mind that form can be handled in angular:

  1. using form tag:
<form #myForm>
 <!-- here some other controls -->
 <button (click)="myForm.reset(); resetView()">Reset</button>
</form>
  1. using ngModel:
 <input [(ngModel)]="myInput1"/>
 <input [(ngModel)]="myInput2"/>
 <!-- here some other controls -->
 <button (click)="resetForm(); resetView()">Reset</button>
resetForm(){
  this.myInput1 = '';
  this.myInput2 = '';
  // etc.
}
resetView(){
  // Some method
}
  1. using FormGroup:
<div [formGroup]="myForm">
 <input formGroupName="myInput1"/>
 <input formGroupName="myInput2"/>
 <!-- here some other controls -->
 <button (click)="resetForm(); resetView()">Reset</button>
</div>
readonly myForm = new FormGroup({
  myInput1: new FormControl(''),
  myInput2: new FormControl(''),
  // etc.
});

resetForm(){
  this.myForm.reset();
}
resetView(){
  // Some method
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda