rio
rio

Reputation: 807

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?

Upvotes: 3

Views: 13286

Answers (1)

Abel Valdez
Abel Valdez

Reputation: 2408

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.

Upvotes: 4

Related Questions