Home:ALL Converter>Angular Reactive Form Submission Event

Angular Reactive Form Submission Event

Ask Time:2019-02-14T04:32:03         Author:Ben Racicot

Json Formatter

I've built a validation component that works great. However, I'd like to extend it by adding success messages when a form is submitted successfully.

In the component I pass in the form, watch for changes, and act on the error:

this.formGroup.valueChanges.pipe(takeUntil(this.ngUnsubscribe)).subscribe(data => {
    if (this.formGroup.invalid) {
        this.validation = { message: `Check for errors in the form`, valid: false };
    } else {
        this.validation = { message: '', valid: true };
    }
});

However I can't see a direct way to get a submission event into my component so that I can show success in the ui.

  1. Can I use the (ngSubmit) event somehow?
  2. what would you do to get it?

UPDATE:

  1. After significant time invested into this my feature request is here

  2. Wrote about "success handling" on Medium

  3. (2022) we finally have the ng-submitted class (v12.1)

Author:Ben Racicot,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/54678936/angular-reactive-form-submission-event
Sergio Contreras Sustaita :

I don't know any submission event directly from the FormGroup class, what I know is that you should listen it from the form template.\n\n<form [formGroup]=\"formGroup\" (ngSubmit)=\"submit()\">\n <!-- Your controls here-->\n <button>Submit</button>\n</form>\n\n\nIn your component code you should listen the submit event creating the submit() method",
2019-02-13T20:56:10
yy