khan
khan

Reputation: 27

ERROR TypeError: Cannot read property - fetch from firestore

I attempted *ngIf validation data from Firestore. few users have only head = true data in firestore. need to validate every user has head = true. but, remaining users dnt have head = true, so error showing link this.

ERROR TypeError: Cannot read property 'head' of undefined

i try to solve this issue below

*ngIf="(access.access$ | async)?.role.head || null".

but except solution like this *ngIf="(access.access$ | async)?.role.(head || null)"

beginner at angular help me find out solution.

thanks in advance.

Upvotes: 0

Views: 148

Answers (1)

Soni Sol
Soni Sol

Reputation: 2612

The issue is happening due to role is undefined,

what you can do to avoid the issue is to use safe navigation ? the line would be:

ngIf="(access.access$ | async)?.role?.head || null"

This way if role is undefined the code will not crash.

Upvotes: 1

Related Questions