Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

form submit with angular material

hey for some reason I cannot submit my form can anyone explain why? I'm using Angular Material.

html:

<mat-dialog-content>

<form class="example-form"[formGroup]="movieForm" (ngSubmit)="addMovie(movieForm.value)">

    ......


<button mat-button type="submit" [disabled]="!movieForm.valid" [mat-dialog-close]="true">Save</button>
<button mat-button [mat-dialog-close]="true">Cancel</button>
</form>
</mat-dialog-content>

and this is the component:

addMovie(form) {
    console.log("check");
  }

How come I cant see the console.log?

like image 947
hindi1991 Avatar asked Feb 07 '26 01:02

hindi1991


1 Answers

Actually you don't need to pass any parameter because you already have the movieForm references in you component.ts .just do the following:

Template html

   <form (ngSubmit)="addMovie()"> 

Component.ts

  addMovie() {
    console.log(this.movieForm);
  }

To access directly to your values check the console object result structure. You will see all the properties that you can access.

like image 82
Abel Valdez Avatar answered Feb 09 '26 07:02

Abel Valdez



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!