← Back to Articles         
AsyncPipe in Angular

AsyncPipe in Angular

Published on 01 Oct 2026     6 min read Angular
HTTP & Web API Integration

What is AsyncPipe in Angular?

1. What is AsyncPipe?

AsyncPipe is a built-in Angular pipe used to subscribe to asynchronous data directly from the template.

It is commonly used with:

  • Observable
  • Promise

Basic syntax:

{{ observable$ | async }}

Instead of manually subscribing in the TypeScript component, Angular's AsyncPipe handles the subscription for us.


2. Why Do We Need AsyncPipe?

Suppose a service returns an Observable:

users$ = this.userService.getUsers();

Without AsyncPipe, we may manually subscribe:

this.userService.getUsers().subscribe(data => {
  this.users = data;
});

Then we also need to consider subscription cleanup when appropriate.

With AsyncPipe:

{{ users$ | async }}

Angular handles the subscription automatically.

So the main purpose is:

Subscribe to asynchronous data in the template and automatically display the latest emitted value.


3. Full Simple Sample Program

Let's use RxJS of() to keep the example simple.

app.ts

import { Component } from '@angular/core';
import { AsyncPipe } from '@angular/common';
import { Observable, of } from 'rxjs';
import { delay } from 'rxjs/operators';

@Component({
  selector: 'app-root',

  imports: [
    AsyncPipe
  ],

  templateUrl: './app.html'
})
export class App {

  message$: Observable<string>;

  constructor() {
    this.message$ = of('Welcome to Angular!')
      .pipe(delay(2000));
  }
}

app.html

<h2>AsyncPipe Example</h2>

<p>
  {{ message$ | async }}
</p>

4. Explanation

First, we create an Observable:

message$: Observable<string>;

The $ at the end is a common naming convention indicating that the variable contains an Observable.

Then:

this.message$ = of('Welcome to Angular!')
  .pipe(delay(2000));

The Observable emits:

Welcome to Angular!

after approximately 2 seconds.

In the template:

{{ message$ | async }}

AsyncPipe subscribes to message$.

Flow

message$
   ↓
Observable
   ↓
AsyncPipe subscribes
   ↓
Observable emits value
   ↓
"Welcome to Angular!"
   ↓
Angular updates template

5. Without AsyncPipe vs With AsyncPipe

Without AsyncPipe

We subscribe manually:

import { Component } from '@angular/core';
import { Observable, of } from 'rxjs';

@Component({
  selector: 'app-root',
  templateUrl: './app.html'
})
export class App {

  message = '';

  constructor() {

    const message$: Observable<string> =
      of('Welcome to Angular!');

    message$.subscribe(value => {
      this.message = value;
    });
  }
}

Template:

{{ message }}

Here we manually call:

.subscribe()

With AsyncPipe

TypeScript:

message$ = of('Welcome to Angular!');

Template:

{{ message$ | async }}

Much simpler.


6. AsyncPipe with HTTP API

A very common real-world use is displaying data returned by HttpClient.

For example:

products$ = this.http.get<Product[]>(
  'https://api.example.com/products'
);

Then:

@for (product of products$ | async; track product.id) {
  <p>{{ product.name }}</p>
}

Here:

HTTP API
   ↓
HttpClient
   ↓
Observable<Product[]>
   ↓
AsyncPipe
   ↓
Products displayed

No manual .subscribe() is required just to display the data.


7. AsyncPipe with @if

Modern Angular control-flow syntax works particularly well with AsyncPipe.

@if (user$ | async; as user) {

  <h2>{{ user.name }}</h2>

  <p>{{ user.email }}</p>

}

Here:

user$ | async

gets the latest value.

Then:

as user

stores that value in the local template variable user.

This avoids repeatedly writing:

user$ | async

8. Automatic Subscription Management

One of the major benefits of AsyncPipe is subscription management.

When Angular creates the component/template:

AsyncPipe
   ↓
Subscribes to Observable

When the Observable emits:

Observable emits
   ↓
AsyncPipe receives value
   ↓
Angular updates the view

When the component/template is destroyed:

Component destroyed
   ↓
AsyncPipe unsubscribes

This reduces the risk of subscriptions remaining active unnecessarily.

It also switches subscriptions appropriately if the bound Observable/Promise reference changes.


9. Advantages

1. No manual subscribe()

Instead of:

observable.subscribe(...)

we can use:

{{ observable | async }}

2. Automatic unsubscribe

Angular handles subscription cleanup when the pipe is destroyed.

3. Cleaner component code

The component can expose an Observable:

users$ = this.userService.getUsers();

and let the template consume it.

4. Automatically displays new values

If the Observable emits:

10
20
30

the UI can update as those values arrive.

5. Works with Observable and Promise

For example:

{{ observable$ | async }}

or:

{{ promise | async }}

10. Disadvantages

1. Template can become complicated

Too many asynchronous expressions such as:

{{ user$ | async }}
{{ products$ | async }}
{{ orders$ | async }}

can make a large template harder to understand.

2. Repeated usage should be considered carefully

Instead of repeatedly writing:

{{ (user$ | async)?.name }}
{{ (user$ | async)?.email }}
{{ (user$ | async)?.city }}

prefer capturing the emitted value:

@if (user$ | async; as user) {

  {{ user.name }}
  {{ user.email }}
  {{ user.city }}

}

This is cleaner and avoids unnecessary repeated pipe evaluation/subscription handling.


11. Key Points

  • AsyncPipe is a built-in Angular pipe.
  • It works primarily with Observable and Promise values.
  • Syntax:
{{ observable$ | async }}
  • It automatically subscribes to an Observable.
  • It returns the latest emitted value.
  • Angular updates the view when new values are emitted.
  • It automatically unsubscribes when the pipe is destroyed.
  • It helps reduce manual subscription-management code.
  • In a standalone component, import:
import { AsyncPipe } from '@angular/common';

and:

imports: [AsyncPipe]

12. Interview Questions and Answers

Q1. What is AsyncPipe in Angular?

AsyncPipe is a built-in Angular pipe that subscribes to an Observable or Promise and returns its latest value to the template.

{{ users$ | async }}

Q2. Why do we use AsyncPipe?

It allows asynchronous data to be consumed directly in the template without manually calling .subscribe() just to display the result.


Q3. Does AsyncPipe automatically unsubscribe?

Yes. When the pipe is destroyed, Angular automatically unsubscribes from the Observable.

This helps prevent unnecessary active subscriptions.


Q4. What types does AsyncPipe support?

Primarily:

Observable
Promise

Q5. subscribe() vs AsyncPipe — what is the difference?

With manual subscription:

this.userService.getUsers().subscribe(users => {
  this.users = users;
});

With AsyncPipe:

users$ = this.userService.getUsers();
{{ users$ | async }}

AsyncPipe is especially convenient when the asynchronous value is needed only for presentation in the template.


Q6. What does $ mean in users$?

users$

The $ has no special meaning to Angular. It is a common naming convention used to indicate that the variable contains an Observable.


Q7. Is AsyncPipe a pure pipe?

Yes. Angular declares AsyncPipe as a pure pipe, but it internally reacts to emissions from the subscribed asynchronous source and marks the component for checking when a new value arrives.


Interview One-Line Answer

AsyncPipe subscribes to an Observable or Promise in the Angular template, returns the latest value, updates the view when new values arrive, and automatically handles subscription cleanup.

← Back to Articles