Submit in Angular form

0 forms events form-submit angular

I am working on Angular 7 forms. I made a whole form with all fields and just added a simple button at the end of this form and now I am wondering how the click on this button is firing the submit action. I have not even set the attribute type="submit" for this button. I have

(ngSubmit)="onSubmit(employeeForm)" 
Run Code Online (Sandbox Code Playgroud)

at the top of my form. Can someone make me understand how any random button is firing this submit functionality. Thanks already.

P.S. I am using Material Design controls in this form.

Sur*_*yan 8

button在html中有两种类型- submitbutton。如果您有一个表单,并且其中有一个类型为的按钮,则submit单击该按钮将强制该表单提交。因此,如果您不想提交,则需要将按钮的类型更改为button

<button mat-button class="btn btn-primary btn-sm" type="button">Save and Next</button>
Run Code Online (Sandbox Code Playgroud)