我想在JSON響應對象數組環在JSON數組使用打字稿
JSON響應循環:
{
"$id": "1",
"Council_ID": 116,
"number": "67",
"subjects": [
{
"$id": "2",
"subjectCode": "67",
"type": 4,
},
{
"$id": "3",
"subjectCode": "67",
"type": 4,
}
]
}
model.component.ts:
this.dataStorageService.storeSubjects(newSubject, this.meetingID)
.subscribe(
response => {
this.dataStorageService.getCouncilId(this.meetingID).subscribe(response => {
this.subjectsWithID = response.json();
this.sublength = this.subjectsWithID.subjects.length;
console.log(this.sublength);
for(let i = 0 ; i <= this.sublength; i++){
this.typee = this.subjectsWithID.subjects[i].type;
this.dataStorageService.getSubjectTypeId(this.typee).subscribe(response =>{
this.namesOfSub = Array.of(response.json());
console.log(this.namesOfSub)
});
}
// console.log(this.typee, 'bla bla');
});
this.addSubjectForm.reset();
this.router.navigate(['/model']);
return true;
這給我的錯誤: - 屬性'主題'在類型'any []'上不存在。有任何建議擺脫這個錯誤?
告訴你subjectsWithID – Sajeetharan
您使用的HttpClient如何申報? –
@Sajeetharan的學科無法讓我看看這個Json迴應我張貼了 –