【问题标题】:TypeError: "setting getter-only property "value"类型错误:“设置 getter-only 属性“值”
【发布时间】:2019-03-30 15:07:51
【问题描述】:

我正在尝试更新输入值,但它返回此错误: TypeError:“设置 getter-only 属性“值” 我在角度创建了一个函数来尝试修改值:

modifyValue(searchCenter, centerId){
    searchCenter.value = centerId._id;
  }

centerId 是我要指定给输入值的值。

这是html:

<p>
      <label>Search a center</label>
      <input type="text" name="searchCenter" class="form-control" #searchCenter='ngModel' [(ngModel)]="term" [(ngModel)]="user.center" required/>

    </p>

   <div class="center panel panel-default"  *ngFor="let center of centers | filter:term">
      <div class="panel-body">

          <button (click)="modifyValue(searchCenter, center)" type="button" class="centers-button">{{center.name}}, {{center.community}},
          {{center.municipality}}</button>

      </div

>

【问题讨论】:

  • #searchCenter 如果类型为NgModel。您可能只想在输入中包含 #searchCenter(没有 ="ngModel" 部分)。还有两个[(ngModel)] 似乎……不正常。

标签: html node.js angular typescript


【解决方案1】:

问题

您试图设置 string 对象的 value 属性是错误的。 string 没有任何名为 value 的属性。

修复

您可能正在尝试设置term 的值。你有两种选择-

  1. 第一次更改

html中的变化

#searchCenter='ngModel'

#searchCenter

2.第二个选项是改变ts文件

modifyValue(searchCenter, centerId){
    this.term = centerId._id;
  }

【讨论】:

    猜你喜欢
    • 2021-11-27
    • 2020-06-16
    • 2019-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-02
    • 1970-01-01
    相关资源
    最近更新 更多