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.

Stuck? AI Nudge Available

Get a conceptual hint to guide your logic without spoiling the final implementation.

03

Study the solution

The solution is waiting

Give it an honest attempt first — then compare your thinking with the full walkthrough.

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.