How can I clear the fields of a form with Angular2? I need to reset the form
I'm using the final version of angular 2 in my project
How can I clear the fields of a form with Angular2? I need to reset the form
I'm using the final version of angular 2 in my project
The fields on your form are linked to a template, right?
<input type="text" [ngModel]="cadastro.nome" name="cadastro-nome />
Place a call to a method:
<button (click)="resetForm">Redefinir</button>
And in the method code, redefine your model:
resetForm(){
this.formulario = {
nome:' '
}
}
If the structure of your form is in a class, you can do the following:
resetForm(){
this.formulario = new Formulario();
}