@oguzhan18/angular-control-flow

ALWAYS use when working with Angular Control Flow syntax, @if, @for, @switch, @defer, or new template syntax in Angular applications.

View in AI SkillSafe app
Scanned · no findings
0 downloads
0 stars
0 demos
SKILL.md
nameangular-control-flow
descriptionALWAYS use when working with Angular Control Flow syntax, @if, @for, @switch, @defer, or new template syntax in Angular applications.

Angular Control Flow

Version: Angular 17+ (2025) Tags: Control Flow, @if, @for, @switch, @defer

References: Control FlowDeferrable Views

API Changes

This section documents recent version-specific API changes.

  • NEW: @if replaces *ngIf — New control flow syntax

  • NEW: @for replaces *ngFor — New loop syntax with track

  • NEW: @switch replaces ngSwitch — New switch syntax

  • NEW: @defer — Lazy load components

  • DEPRECATED: *ngIf, *ngFor, *ngSwitch — Migrate to new syntax

Best Practices

  • Use @if for conditionals
@Component({
  template: `
    @if (isLoggedIn) {
      <p>Welcome!</p>
    } @else {
      <p>Please login</p>
    }
  `
})
export class MyComponent {
  isLoggedIn = signal(false);
}
  • Use @else if
@Component({
  template: `
    @if (user.role === 'admin') {
      <p>Admin panel</p>
    } @else if (user.role === 'user') {
      <p>User dashboard</p>
    } @else {
      <p>Guest view</p>
    }
  `
})
export class MyComponent {}
  • Use @for for loops
@Component({
  template: `
    @for (item of items; track item.id) {
      <li>{{ item.name }}</li>
    }
  `
})
export class MyComponent {
  items = [{ id: 1, name: 'A' }, { id: 2, name: 'B' }];
}
  • Use track for performance
@for (user of users; track user.id) {
  <li>{{ user.name }}</li>
}
  • Use @empty for empty lists
@Component({
  template: `
    @for (item of items; track item.id) {
      {{ item.name }}
    } @empty {
      <p>No items found</p>
    }
  `
})
export class MyComponent {}
  • Use @switch for conditionals
@Component({
  template: `
    @switch (status) {
      @case ('loading') {
        <p>Loading...</p>
      }
      @case ('success') {
        <p>Success!</p>
      }
      @case ('error') {
        <p>Error occurred</p>
      }
      @default {
        <p>Unknown status</p>
      }
    }
  `
})
export class MyComponent {
  status = 'loading';
}
  • Use @defer for lazy loading
@Component({
  template: `
    @defer (on viewport) {
      <heavy-chart />
    } @placeholder {
      <div>Loading chart...</div>
    }
  `
})
export class DashboardComponent {}
  • Use @defer with conditions
@Component({
  template: `
    @defer (on hover) {
      <tooltip />
    }
    
    @defer (when isReady) {
      <ready-component />
    }
  `
})
export class MyComponent {}
  • Migrate from *ngIf
ng generate @angular/core:control-flow
  • Use else with @if
@if (condition) {
  content
} @else {
  alternative
}

Embed badges

Add these to your README to show the skill's verification status.

SkillSafe verified badge
Verified badge
[![SkillSafe verified badge](https://api.skillsafe.ai/v1/badge/@oguzhan18/angular-control-flow/verified)](https://skillsafe.ai/skill/@oguzhan18/angular-control-flow/)
Installs badge
Installs badge
[![Installs badge](https://api.skillsafe.ai/v1/badge/@oguzhan18/angular-control-flow/installs)](https://skillsafe.ai/skill/@oguzhan18/angular-control-flow/)
Scan badge
Scan badge
[![Scan badge](https://api.skillsafe.ai/v1/badge/@oguzhan18/angular-control-flow/scan)](https://skillsafe.ai/skill/@oguzhan18/angular-control-flow/)
Eval pass rate badge
Eval pass rate
[![Eval pass rate badge](https://api.skillsafe.ai/v1/badge/@oguzhan18/angular-control-flow/eval)](https://skillsafe.ai/skill/@oguzhan18/angular-control-flow/)