【问题标题】:Mat Input two way binding to value property not workingMat Input 两种方式绑定到值属性不起作用
【发布时间】:2018-10-02 20:04:51
【问题描述】:

我创建了一个 Mat Input 控件,并将它的 value 属性与我的控制器上的一个属性进行了 2 路绑定,但是当我输入输入时,绑定的属性没有更新。

堆栈闪电战链接: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>

为什么绑定的属性没有更新?

【问题讨论】:

    标签: angular angular6


    【解决方案1】:

    使用[(ngModel)] 代替[(value)](有关演示,请参阅this stackblitz)。

    <input matInput placeholder="Input" [(ngModel)]="currentValue">
    

    This article 解释了如何使用[value](input) 的组合获得等效行为。

    【讨论】:

    猜你喜欢
    • 2017-04-06
    • 1970-01-01
    • 2013-08-15
    • 1970-01-01
    • 1970-01-01
    • 2020-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多