A lot of angular tutorial has suggest to use async pipe for auto unsubsribing observable.
What they claim:
async pipe is used for auto unsubscribing observer, or else you need to unsubscribe manually
What they did:
They use angular http
to call REST api as an example for async
pipe.
However, from my understanding, angular HTTP auto unsubscribe the observable. So, async pipe actually did not serve the intended purpose here as the observable will auto unsubscribe even without async pipe.
Is there any other reason why need to use async pipe here in this use case?
Sample implementation:
getUserList() {
return this.http.get(apiUrl);
}
this.getUserList().subscribe(user => {
this.userList = user;
});
<div *ngFor="let user of userlist | async">
{{ user?.name }}
{{ user?.email }}
</div>