Stack Overflow Asked on December 13, 2020
Could someone explain what might have went wrong ? I am getting this error
ERROR TypeError: Cannot read property 'codeSprint' of undefined
at Object.eval [as updateRenderer] (SprintComponent.html:12)
at Object.debugUpdateRenderer [as updateRenderer] (core.js:45294)
at checkAndUpdateView (core.js:44277)
in SprintComponent.html :
<div ngFor="let sprint of sprints">
{{sprint.codeSprint}}
{{sprint.title}}
</div>
in SprintComponent.ts:
sprints : Sprint[];
in SprintService.ts:
getSprints(): Observable<Sprint[]> {
const token = localStorage.getItem('kno');
const rqwstrId = localStorage.getItem('rqwstrId');
let header = new HttpHeaders('Content-Type: application/json; charset=UTF-8');
header = header.append('kno',token);
header = header.append('rqwstrId', rqwstrId);
let param = new HttpParams().set('code',"Koon52");
return this.http.get<Sprint[]>(this.baseUrl + '/v1/sprints/', {headers : header , params : param});
}
with Sprint as an class with following properties:
export class Sprint {
kno:string;
rqwstrId : string;
code: string;
codeSprint : string;
dateDebut : string;
dateFin : string;
title : string;
constructor() {
}
}
meanwhile when i log it in the console, it displays the data like this:
SprintComponent.html:9 ERROR TypeError: Cannot read property 'codeSprint' of undefined
at Object.eval [as updateRenderer] (SprintComponent.html:9)
at Object.debugUpdateRenderer [as updateRenderer] (core.js:45294)
at checkAndUpdateView (core.js:44277)
at callViewAction (core.js:44637)
at execComponentViewsAction (core.js:44565)
at checkAndUpdateView (core.js:44278)
at callViewAction (core.js:44637)
at execEmbeddedViewsAction (core.js:44594)
at checkAndUpdateView (core.js:44272)
at callViewAction (core.js:44637)
I call getSprints method in SprintComponent like this :
ngOnInit() : void {
this.sprintService.getSprints().subscribe(
data =>
{
this.sprints = data;
}
);
And Thanks!
You need to subscribe the methode in your component
sprints:any[]=[];
in your ngoninit
this.service.getSprints().subscribe((response) => {
this.sprints=response as any
});
)}
in your component.html
<div *ngFor="let sprint of sprintd">
{{sprint.codeSprint}}
{{sprint.title}}
</div>
Answered by Sohaib El Mediouni on December 13, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP