Angular Components
ASecurityUse Angular's built-in control-flow blocks (Angular 17+) instead of the structural directives `*ngIf` and `*ngFor`. Always give `@for` a stable tracking expression, normally a unique item id, and provide an `@empty` state when an empty collection needs a useful UI. ```ts import { ChangeDetectionStrategy, Component, input } from '@angular/core'; interface User { id: string; name: string; } @Component({ selector: 'app-user-list', standalone: true, imports: [], changeDetection: ChangeDetectionSt...
- 584 stars
- 0 votes
- 0 copies
- 2 views
- Added September 5, 2026
Security analysis
100/100Pro scans all 21 files and shows the line behind each finding
npx -y skills add HoangNguyen0403/agent-skills-standard --skill angular-components --agent claude-codeAre you the author of Angular Components?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/hoangnguyen0403-angular-components-eb05c217)# Using `@if` and `@for` in Angular templates
Use Angular's built-in control-flow blocks (Angular 17+) instead of the structural directives `*ngIf` and `*ngFor`. Always give `@for` a stable tracking expression, normally a unique item id, and provide an `@empty` state when an empty collection needs a useful UI.
```ts
import { ChangeDetectionStrategy, Component, input } from '@angular/core';
interface User {
id: string;
name: string;
}
@Component({
selector: 'app-user-list',
standalone: true,
imports: [],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
@if (loading()) {
<p>Loading users...</p>
} @else {
@for (user of users(); track user.id) {
<article>
<h2>{{ user.name }}</h2>
</article>
} @empty {
<p>No users found.</p>
}
}
`,
})
export class UserListComponent {
readonly loading = input(false);
readonly users = input.required<readonly User[]>();
}
```
`@if` can have `@else if` and `@else` branches. A `@for` block can use `let` aliases and an `@empty` block; `track user.id` lets Angular reuse DOM nodes correctly when the array changes. Read signal inputs with `users()` and `loading()`, rather than treating them as ordinary properties. The component remains standalone and uses `OnPush`.
Files in this skill
- eval-1.baseline.md
- eval-1.with-skill.md
- eval-2.baseline.md
- eval-2.with-skill.md
- eval-3.baseline.md
- eval-3.with-skill.md
- eval-4.baseline.md
- eval-4.with-skill.md
- eval-5.baseline.md
- eval-5.with-skill.md
- eval-6.baseline.md
- eval-6.with-skill.md
- eval-7.baseline.md
- eval-7.with-skill.md
- eval-8.baseline.md
- eval-8.with-skill.md
- eval-9.baseline.md
- eval-9.with-skill.md
- trigger-1.md
- trigger-2.md
Attribution
Related skills
View all in development →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.