0
votes

In my template...

<input matInput placeholder="Amount" [(value)]="amount">

In my component...

class ExampleComponent implements OnInit {
    amount: number = 0;
    ...
}

This doesn't bind.

I've also tried this in my template...

<input matInput placeholder="Amount" [(ngModel)]="amount">

Which causes the following error on compile...

Can't bind to 'ngModel' since it isn't a known property of 'input'.

1
Have you added FormsModule to your project? - Sunny Parekh
add FormsModule in imports array of NgModule inside app.module.ts - canbax

1 Answers

1
votes
<input matInput placeholder="Amount" [(ngModel)]="amount">

Above is the correct statement for two way data binding. You need to import FormsModule in app.module.ts

After importing, include FormsModule in imports array of NgModule decorator.

Please find here the working stackblitz: https://stackblitz.com/edit/angular-ngmodel-form-mhop4i