Skip to solution
hardFrontend

What are Deferrable Views (@defer) and how do they work in Angular 17+?

1.2k views
01

Understand the problem

Explain how Deferrable Views allow lazy loading of template sections dynamically.

performanceroutingdefer
02

Attempt it yourself

Sketch your approach before reading the solution — that's what interviews test.

Nudge consolestandby

Stuck? Beam a request up — the console returns a conceptual nudge that guides your logic without spoiling the implementation.

03

Study the solution

Deferrable Views allow developers to lazily load component, directive, and pipe dependencies directly from templates using the @defer block. Triggered by conditions like viewport, hover, or custom logical expressions, it splits the application bundle automatically to optimize page load.

Solution ready — 2 min read

Classified // press E to declassify

04

Read the code

Deferrable view with viewport and placeholder triggers
import { Component } from '@angular/core';
import { HeavyChartComponent } from './heavy-chart.component';

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [HeavyChartComponent],
  template: '<h2>Dashboard</h2>' +
    '<div style="height: 1200px;">Scroll down to see chart...</div>' +
    '@defer (on viewport) {' +
    '  <app-heavy-chart></app-heavy-chart>' +
    '} @placeholder {' +
    '  <div class="skeleton">Loading placeholder...</div>' +
    '} @loading {' +
    '  <p>Fetching chart bundle...</p>' +
    '} @error {' +
    '  <p>Failed to load chart dependencies.</p>' +
    '}'
})
export class AppComponent {}
05

Join the discussion

Discussion (0)

Sign in to join the discussion.

No responses yet. Be the first to share what you think.

Transmission complete // awaiting log

KEEP THE
STREAK ALIVE.

Dossier 81 of 121 decoded in the Angular track. One more won't hurt.

Back to track