0

I am subscribing to my data from an http get method:

  getEds(): void {
    this.edService.getEds()
      .subscribe((eds: Education) => {
        this.eds = eds.educationData;
        console.log(this.eds:codeschool);
      });
  }

I am trying to display my courses for codeschool in an *ngFor loop but do not know how to access the data. My console log will show the entire array of objects so I know I am receiving the correct info. I've tried various syntax:

.subscribe((eds: any) => {
            this.eds = eds.educationData.course;

.subscribe((eds: any) => {
            this.eds = eds.educationData['codeschool'];

.subscribe((eds: any) => {
            this.eds = eds.educationData.codeschool;

None of these syntax work and the log shows undefined. I found this page which has great info and what I tried to use as a baseline.

Access / process (nested) objects, arrays or JSON

However, I do not know what is wrong or why I cannot get the data I need. When I use

  .subscribe((eds: any) => {
    this.eds = eds.educationData;

and I log out (this.eds), my log shows:

[{…}] 
0:{codeschool: Array(14), egghead: Array(6)}
 length:1
 __proto__:Array(0)

Beyond this I haven't been able to get the data I want...... :(

baao
  • 71,625
  • 17
  • 143
  • 203
Cuong Vo
  • 249
  • 1
  • 6
  • 16
  • It seems this getEds() returns an array; so, as explained by @Sidhanshu_, you can access each item by its index. – Christian Benseler Jun 07 '18 at 17:47
  • Possible duplicate of [Access / process (nested) objects, arrays or JSON](https://stackoverflow.com/questions/11922383/access-process-nested-objects-arrays-or-json) – baao Jun 07 '18 at 17:47
  • Please use tags carefully. Your question has nothing to do with angular. – baao Jun 07 '18 at 17:47

1 Answers1

3

use this :

eds.educationData[0].codeschool
baao
  • 71,625
  • 17
  • 143
  • 203
Sidhanshu_
  • 1,714
  • 1
  • 7
  • 10