Angular course ยท Module 14: Advanced Patterns

The Future of Angular

3 min read ยท
In this lesson6

Angular keeps evolving - like a samurai perfecting his skills throughout his entire life.

Zoneless Angular (Angular 18+)

// app.config.ts
import { provideExperimentalZonelessChangeDetection } from '@angular/core';

export const appConfig: ApplicationConfig = {
  providers: [
    provideExperimentalZonelessChangeDetection()
  ]
};

// Components must use Signals or manual markForCheck
@Component({
  selector: 'app-counter',
  template: `
    <p>Count: {{ count() }}</p>
    <button (click)="increment()">+1</button>
  `
})
export class CounterComponent {
  count = signal(0);

  increment(): void {
    this.count.update(c => c + 1);
  }
}

This is the Angular 19 version, where the function still has Experimental in its name. Angular 20 renamed it to provideZonelessChangeDetection() (stable since 20.2), and since Angular 21 zoneless is the default. So check the version in package.json: in Angular 19 you write provideExperimentalZonelessChangeDetection(), in newer versions provideZonelessChangeDetection().

Signals - Full Integration

// Angular 19+ features
import { signal, computed, effect, linkedSignal, resource } from '@angular/core';

@Component({...})
export class FutureComponent {
  // linkedSignal - resets when source changes
  userId = input.required<number>();
  selectedTab = linkedSignal({ source: this.userId, computation: () => 'profile' });  // Resets on userId change

  // resource() - declarative data fetching
  userResource = resource({
    request: () => this.userId(),
    loader: async ({ request: id }) => {
      const response = await fetch(`/api/users/${id}`);
      return response.json();
    }
  });

  // The previous value comes from linkedSignal (computed() does not get it)
  count = signal(0);
  changes = linkedSignal<number, { current: number; previous: number }>({
    source: this.count,
    computation: (current, prev) => ({ current, previous: prev?.value.current ?? 0 })
  });
}

Partial Hydration (Experimental)

// Selective hydration - only interactive parts
@Component({
  template: `
    <!-- Static content - no JS needed -->
    <header>{{ title }}</header>

    <!-- Hydration on interaction -->
    @defer (hydrate on interaction) {
      <app-interactive-widget />
    }

    <!-- Hydration when visible -->
    @defer (hydrate on viewport) {
      <app-comments />
    }
  `
})
export class HybridComponent {}

esbuild and Vite (Angular 17+)

Since Angular 17, new projects use the application builder: esbuild bundles the production build, and Vite only acts as the development server in ng serve. Since Angular 18 this builder also ships in a separate @angular/build package, as in this example:

// angular.json - application builder: esbuild bundles the app, Vite only serves it in ng serve
{
  "architect": {
    "build": {
      "builder": "@angular/build:application"
    }
  }
}

Best Practices in Angular 19

  1. Standalone Components - default, NgModules optional
  2. Signals - preferred over RxJS for component state
  3. Functional Guards/Resolvers - instead of classes
  4. Control Flow - @if, @for, @switch instead of directives
  5. inject() - instead of constructor injection
  6. TypeScript Strict - full type control
  7. ESLint - instead of TSLint
  8. Zoneless - for maximum performance

Journey Summary

Congratulations, Angular master!

You have learned:

  • TypeScript and Standalone Components
  • Signals and reactivity
  • RxJS and reactive programming
  • Reactive forms
  • Routing and Guards
  • Services and Dependency Injection
  • State Management
  • HttpClient and API
  • Testing
  • Security and performance
  • Styling and animations
  • Advanced patterns

Ganbatte! (Good luck!)

The path of a samurai never ends - Angular keeps evolving, so keep learning!

Spotted a mistake in this lesson?

Check yourself

Answer the questions from this lesson. Pick an answer to see right away whether it is correct.

  1. 1. What is required for an Angular application to run in zoneless mode?

  2. 2. Which of the following is NOT recommended in Angular 2024+?

These are 2 of 5 questions for this lesson. Solve the rest in the game.

Hands-on tasks in the game

  • Code editor

    Complete the Angular application configuration in zoneless mode.

  • Horizontal ordering

    Arrange the partial hydration expression that triggers on interaction (one line, left to right):

  • Click in order

    Click the elements in order to build the call that enables zoneless mode: provideExperimentalZonelessChangeDetection()

  • Click in order

    Click the elements in order to build the opening of a conditional block: @if (isVisible()) {

  • Vertical ordering

    Order the recommended approaches from the oldest (legacy) to the newest (recommended):

  • Click in order

    Click the elements in order to build the call for a signal that resets when its source changes: linkedSignal(...)

  1. QuestionZoneless Angular
  2. QuestionBest Practices
  3. QuestionDeclarative data fetching
  4. Coding taskPractice: Zoneless Config
  5. Put in orderHydration on interaction
  6. QuestionBundler in Angular
  7. Click in orderZoneless configuration
  8. Click in orderModern control flow
  9. Put in orderEvolution of the Angular approach
  10. Click in orderSignal that resets when its source changes
  11. QuestionPurpose of zoneless mode
  12. VideoModule Summary

Useful articles