无法读取未定义的属性“值”

时间:2017-11-03 06:27:24

标签: angular typescript html-table

我收到一条错误消息,上面写着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>

如果需要更多代码段,请告诉我。

谢谢。

1 个答案:

答案 0 :(得分:1)

它的拼写错误,请更改

UpdScore.value

updScore.value