Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reset ONLY a specific ngModelGroup fields in Angular 2.1.1?

i have this simple code:

<form #form="ngForm" (ngSubmit)="submit(form)">
   <fieldset ngModelGroup="cliente">
      // inputs with ngModel
   </fieldset>
   <fieldset ngModelGroup="enderecos">
      // inputs with ngModel
   </fieldset>
   <fieldset ngModelGroup="contatos">
      // inputs with ngModel
   </fieldset>
</form>

// My submit method
submit(form: NgForm) {
  if(form.valid) {
    // save
    // reset method
    form.reset();
  }
}

When i call the method form.reset(), Angular reset all the fields by default.

My question is: Does have any chance to reset ONLY a specific ngModelGroup like "contatos" or "enderecos" and not all the form inputs?

Thanks in advise.

like image 895
Tiago Cássio Avatar asked Feb 05 '23 16:02

Tiago Cássio


1 Answers

I think i solve done this on my method:

form.controls['contato'].reset();

'contato' is a ngModelGroup on my form.

like image 199
Tiago Cássio Avatar answered Mar 21 '23 03:03

Tiago Cássio