As im new to the angular. I just want to get the value from the mat-input I need to get the value from the angular mat-input. Can someone help me to do this. Thanks in advance
<div fxLayoutAlign= "center center" fxFlexFill class="main-div">
<mat-card fxFlex= "20">
<mat-toolbar color="primary" c>Bonbloc Login</mat-toolbar>
<form fxLayoutAlign="stretch" fxLayout = "column" class="login-form">
<mat-form-field>
<input matInput required [(ngModel)] = "email" placeholder="email Id">
<mat-hint align="end">Min 5 characters</mat-hint>
</mat-form-field>
<mat-form-field>
<input matInput required [(ngModel)] = "password" type="password" placeholder="password">
</mat-form-field>
<button mat-raised-button type="submit" (click) = "login()">Login</button>
<h1>Hi {{email}} {{password}}</h1>
</form>
</mat-card>
login() {
console.log(this.email, this.password)
};
What part of it isn't working exactly? It looks as though it should be fine.
Presumably you have a matching line in the
.ts
declaring anemail
field to bind to:Or similar.
[(ngModel)]
Is a two-way binding, meaning whatever you setemail
to programmatically will be put into the text box, and whatever the user puts into the text box will setemail
's value.Your
login()
method should be able to see this...Edit: Example StackBlitz showing the basic binding working. Not using
matInput
, but that won't change the functionality.