4

CUSTOM COMPONENT

// ...

@Output() submit: EventEmitter < any > = new EventEmitter();

// ...

onFilterSubmit($event): void {
  this.submit.emit($event);
  this.formData = {
    minDate: new Date().toISOString(),
    maxDate: new Date().toISOString()
  };
}
<form (ngSubmit)="onFilterSubmit(formData)">

    <!-- -- -->
    <button mat-button
        mat-raised-button
        [disabled]="reqsForm.form.invalid" 
        type="submit"
        color="primary">
        {{labels.submit}}
    </button>
</form>

OUTER COMPONENT

// ...

onFilterSubmit($event): void {
  console.info("FORM SUBMIT", $event);
}
<custom-component (submit)="onFilterSubmit($event)">

  <!-- -- -->

</custom-component>

OUTPUT

FORM SUBMIT > Object

FORM SUBMIT > Object

Sampgun
  • 2,822
  • 1
  • 21
  • 38

1 Answers1

7

The reason why this was happening is that an event called "submit" is catchable already from outside the custom component.

I solved by changing the custom event name to filterSubmit

Note also that the type submit on the button - in this use case - is virtually useless, since as default one button in a form will be of type submit.

Sampgun
  • 2,822
  • 1
  • 21
  • 38