How can I loop through the subjects array in a JSON response?
JSON Response:
{
"$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;
How can I fix the error: "Property 'subjects' does not exist on type 'any[]'. Is there any suggestion to get rid of this error?