good afternoon developers, i have fetch data from my api and the data is responded as below
{id: 1, owner: "2", amount: "0", created_at: "2020-09-14 11:04:12", updated_at: "2020-09-14 11:04:12"}
and my code is below
return this.http.post(this.env.API_URL + "auth/wallet", { id: this.user['id'], }).subscribe(res => { this.wallet = res[0]; console.log(this.wallet); }, (err) => { console.log(err); });
when i type {{wallet[“amount”}} it returns Cannot read property ‘amount’ of undefined
Advertisement
Answer
You probably need to use the optional chaining operator with dot notation like this:
{{wallet?.amount}}
This will not throw an error when the value is undefined, because it IS undefined until your API request is completed. By the way, this has nothing to do with Ionic, it’s more of an Angular thing.