【问题标题】:Cannot read property 'value' of undefined in无法读取未定义的属性“值”
【发布时间】:2017-11-03 14:29:19
【问题描述】:

我收到一条错误消息,上面写着 ERROR TypeError: Cannot read property 'value' of undefined. 我正在使用 Angular CLI、Typescript 和 HTML-Table。我检查了代码,但我认为它不是由拼写错误引起的。谁能帮我解决这个错误?

//function in typescript
updStudent(newName: string, newYear: string, newSemester: string, newScore: string) {
  this.stockService.updStudent(this.selectedStudent.id, newName, newYear, newSemester, newScore).subscribe;
}
loadStu(Student: any) {
  this.updateEnable = true;
  this.selectedStudent = Student;
}
<!--button-->
<button type="button" (click)="loadStu(Student)">UPDATE</button>
<hr>

<!--form-->
<div *ngIf="updateEnable">
  id: <input disabled [value]="selectedStudent.id" />
  <br>name: <input name="name" #updName [value]="selectedStudent.name" />
  <br>year: <input name="year" #updYear [value]="selectedStudent.year" />
  <br>semester: <input name="semester" #updSemester [value]="selectedStudent.semester" />
  <br>score: <input name="score" #updScore [value]="selectedStudent.score" />
  <br><button type="button" (click)="updStudent(updName.value, updYear.value, updSemester.value, UpdScore.value)">SAVE</button>
</div>

如果需要更多的 sn-ps,请告诉我。

谢谢。

【问题讨论】:

    标签: angular typescript html-table


    【解决方案1】:

    错别字,请改

    UpdScore.value
    

    updScore.value
    

    【讨论】:

    • 哇,这真是一个错字,请原谅我的粗心。谢谢你的回答:)
    • 我可以在一分钟内接受我点击检查按钮时说的答案,请稍候,我会尽快接受 :)
    猜你喜欢
    • 2023-03-11
    • 2011-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-06
    • 2020-11-10
    • 2018-05-03
    相关资源
    最近更新 更多