It’s important to remember that using | async creates a
subscription if the source is an Observable. Thankfully, when
the component is destroyed the subscription is also managed
and unsubscribed for us!
Check out the live StackBlitz example:
hitps/utimatecourses.comibloglangular-ngfor-asyne-pipe an‘owi2r2020 Handling Observables with NoFor and the Async Pipe - Ulimate Courses ™
4 FREE eBook: @)
ForEach, Map, Filter,
Reduce, Some, Every,
Find
“This book is straight to
the point, syntax
exploration,
comprehensive guide,
real-world examples,
tips and tricks -it covers
all you need
Tadd Motto, author of
Exploring JavaScript Array
Methods
Enter your email Get
my,
FREE
NoFor Template and Async Pipe
eBook
When we think of NgFor, we should think of NgForOf. Here's
how you can use NgFor with the element using
the async pipe:
hitps/utimatecourses.comibloglangular-ngfor-asyne-pipe sm‘owi2r2020 Handling Observables with NoFor and the Async Pipe - Ulimate Courses ™
This is the longer syntax using and explains
why We use “ngFor with the asterisk, which denotes that it’s a
behavioral directive.
Check out the live StackBlitz example:
NoFor + NgIf + Async Pipe
So far we've covered some really nice usage of NgFor with the
async pipe, but now we're going to show a common practice
of “unwrapping” observables on different levels of the
template.
First, using Nglf and the Async Pipe, we can do this:
hitps/utimatecourses.comibloglangular-ngfor-asyne-pipe am‘owi2r2020 Handling Observables with NoFor and the Async Pipe - Ulimate Courses ™
{{ pizza }}
Instead of using the async pipe directly with NgFor, we could
use Nglf to unwrap our Observable into a pizzas variable.
This would allow us to reuse the variable multiple times inside
the template without creating repeat subscriptions: