Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

252
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda