0

I got error from ERROR TypeError: "_co.dashboard is undefined" when I try to call dashboard.all_interviewed in html.

In My dashboard.component.ts

dashboard: Dashboard;

    getDashboard() {
      this.dashboardService.getDashboard().subscribe(
        res => {
            this.dashboard = res;
         }
      )
    }

In Dasboard Class

export class Dashboard {
   all_interviewed: number;
}

dashboard.component.html

<h2>{{ dashboard.all_interviewed }} </h2>

I got this error in console log.

ERROR TypeError: "_co.dashboard is undefined" View_DashboardComponent_0 DashboardComponent.html:208 Angular 32 RxJS 5 Angular 8 DashboardComponent.html:203:11

Chando
  • 424
  • 4
  • 14

2 Answers2

0

Try the following code,

<h2 *ngIf = "dashboard">{{ dashboard.all_interviewed }} </h2>
Abhishek Sharma
  • 319
  • 2
  • 8
0

Call getDashboard() on ngOnInit() and then try this:

<div *ngIf = "dashboard">
   <h2>{{ dashboard.all_interviewed }}</h2>
</div>
Iñigo
  • 1,877
  • 7
  • 25
  • 55