I am working on reactive forms in angular 7, and I need to call submit from a button outside the form.
<input type="button" form="ngForm" class='Button' value="Save" (click)="detailForm.ngSubmit.emit()" />
<form [formGroup]="gDetailForm" (ngSubmit)="onSubmit()" >
</form>
This function is working fine.
Now, I need to submit the form from multiple buttons i.e.
- if user click Save button, the form should be submitted and save
- if user click Update button, the form should be submitted and update
For this purpose, I want to pass a flag 'Save' or 'Update' from
<input type="button" form="ngForm" class='Button' value="Save" (click)="detailForm.ngSubmit.emit('Save')" />
<input type="button" form="ngForm" class='Button' value="Update" (click)="detailForm.ngSubmit.emit('Update')" />
<form [formGroup]="gDetailForm" (ngSubmit)="onSubmit(flag)" >
</form>
But I could not submit the form with the 'Save' / 'Update' flag. How could I pass a parameter from Save and Update buttons outside the form to my submit function.
Any fruitful suggestion would be highly appreciated.
formGroupand anngForm. Is there any reason you can't simply callonSubmit()from the buttons, passing the required flags? - Will Alexander