AnswerBun.com

ERROR TypeError: Cannot read property 'codeSprint' of undefined at Object.eval [as updateRenderer] using Angular

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!

One Answer

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

Add your own answers!

Related Questions

How to Deserialize a list of objects from json in flutter

8  Asked on January 28, 2021 by gainz

     

How to pass input variable in structure directive?

1  Asked on January 27, 2021 by alice-messis

 

How to iterate over a list of floats in python

4  Asked on January 27, 2021 by joeyhoward988

 

Can I run docker system prune -a without downtime

1  Asked on January 27, 2021 by aswin-george

 

Calculating total Price of groceries with execptions in Python

4  Asked on January 27, 2021 by shemtheultimate

 

handling multiple useState inside conditional ternary

2  Asked on January 27, 2021 by kachi-cheong

     

react-native existing app crash on Android 4.1

0  Asked on January 27, 2021 by s-leg3ndz

     

HTML table widths set proportionally

1  Asked on January 27, 2021 by mayur-arora

   

Alsa issues on Raspberry pi

1  Asked on January 27, 2021 by suraj-hebbar-shankar

 

How to merge dictionaries with the same key and value in Python

1  Asked on January 26, 2021 by arbin-bulaybulay

 

AJAX switching HTML

1  Asked on January 26, 2021 by mimi

       

Using request to return a json value

1  Asked on January 26, 2021 by gta-sprx

 

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP