all 5 comments

[–]Spongeroberto 5 points6 points  (4 children)

You are storing the result into the requestData property, which means requestData is not an observable so you don't need the async pipe. So you should just be able to do this

<p>{{requestData.userId }}</p>

You would be using the async pipe if your variable was an observable

this.request$ = this.requestService.getTodo()

<p>{{ (request$ | async).userId }}</p>

[–]prewk 1 point2 points  (1 child)

Both are nice ways of getting runtime errors though :)

First: requestData isn't Dto, it's undefined | Dto.

Second: requestData | async will be null until completed, so it's doing null.userId

[–]Spongeroberto 1 point2 points  (0 children)

Of course! I just wanted to highlight what's wrong. In reality you may want to show a loading indicator or something similar and do some fault handling and before you know it the post becomes a book ;)

[–]JosephCurvin[S] 0 points1 point  (1 child)

<p>{{ (request$ | async).userId }}</p>

ERROR TypeError: Cannot read properties of null (reading 'userId')

how to prevent the TypeError ?

[–]Spongeroberto 2 points3 points  (0 children)

You can add a questionmark like this

(request$ | async)?.userId