Search code examples
angularsubmitform-controlformgroups

Is it possible to access specific formgroup value onsubmit


Inside one component,

there are 2 form groups.

Both form has a submit type input and few form controls.

like below . Form group A and B.

<form [formGroup]...>
  <input formControlName.../><button type="submit" .../>
</form>
<form [formGroup]...>
  <input formControlName.../><button type="submit" .../>
</form>

My question is, how can I access a particular form group value from these two form control, in 1 onSubmit() function ?


Solution

  • Try and use this syntax:

    <form (ngSubmit)="onSubmit(formGroup.value)">
    </form>