I have created a Mat Input control and done a 2 way binding of it's value property to a property on my controller but when I type in the input the bound property is not updated.
Stack blitz link: https://stackblitz.com/edit/angular-7ojsjo
<div class="example-container">
<mat-form-field>
<input matInput placeholder="Input" [(value)]="currentValue">
</mat-form-field>
<h1>{{currentValue}}</h1>
</div>
Why is the bound property not updating?
Use [(ngModel)]
instead of [(value)]
(see this stackblitz for a demo).
<input matInput placeholder="Input" [(ngModel)]="currentValue">
This article explains how the equivalent behavior can be obtained with a combination of [value]
and (input)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With