</>
Skip to content
Angular lessons (36/43)

Angular — Performance

Lazy Loading

const routes: Routes = [
  { 
    path: 'admin', 
    loadChildren: () => import('./admin/admin.module').then(m => m.AdminModule)
  }
];

OnPush Change Detection

@Component({
  selector: 'app-user',
  changeDetection: ChangeDetectionStrategy.OnPush,
  template: `...`
})
export class UserComponent {
  @Input() user: any;
}

TrackBy

<div *ngFor="let item of items; trackBy: trackById">
  {{item.name}}
</div>
trackById(index: number, item: any): number {
  return item.id;
}

OnPush with Signals

@Component({
  selector: 'app-counter',
  changeDetection: ChangeDetectionStrategy.OnPush,
  template: `
    <p>{{count()}}</p>
    <button (click)="increment()">+</button>
  `
})
export class CounterComponent {
  count = signal(0);
  
  increment() {
    this.count.update(c => c + 1);
  }
}

Performance Checklist

TechniqueImpact
Lazy loadingFaster initial load
OnPush detectionLess change detection
trackByFaster list rendering
Async pipeAuto unsubscribing
SignalsFine-grained updates

Mini Practice

  1. Add lazy loading
  2. Use OnPush change detection
  3. Add trackBy to lists
  4. Optimize with signals

Up Next

Continue with Deployment — deploying Angular apps.

Related Topics

Frequently Asked Questions about Performance

What is Performance in Angular?

Performance is a fundamental concept in Angular. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn Performance?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Performance.

Why is Performance important in Angular?

Performance is essential for Angular development. Understanding this concept will help you write better code and solve real-world problems more effectively.