Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mat Input two way binding to value property not working

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?

like image 460
Guerrilla Avatar asked Oct 02 '18 20:10

Guerrilla


1 Answers

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).

like image 162
ConnorsFan Avatar answered Nov 16 '22 01:11

ConnorsFan