Sandeep Nambiar
Sandeep Nambiar

Reputation: 1676

Cannot read property of undefined in angular 6

I am getting Cannot read property of undefined in angular 6 but its value is displaying in template.here is my code

  this.data.post_data('dashboard/gettodaydata','',true)
               .subscribe((data:any) => {
                 this.today_datas =data.data;
              });

and this is my template file

<span class="counter text-danger">{{ today_datas.total_cpc | number }}</span>

Upvotes: 3

Views: 2173

Answers (1)

Pankaj Parkar
Pankaj Parkar

Reputation: 136134

Binding is trying to get evaluate before today_datas gets populated from API call. Use navigation/elvis operator

{{ today_datas?.total_cpc | number }}

Upvotes: 6

Related Questions