Components
Esta página aún no está disponible en tu idioma.
Overview
Section titled “Overview”Components are the fundamental building blocks of Angular applications. Each component encapsulates its own template, logic, and styles into a self-contained, reusable unit. This section covers everything from basic component creation to advanced patterns in Angular 18+.
Available Pages
Section titled “Available Pages”- Fundamentals — Anatomy of a component, creating with CLI, selectors, and styling
- Inputs, Outputs & Two-Way Binding — Signal inputs, function-based outputs, and model inputs
- Templates & Control Flow — Built-in
@if,@for,@switchsyntax - Lifecycle Hooks —
ngOnInit,ngOnDestroy,DestroyRef,afterNextRender - Content Projection — Single-slot and multi-slot
<ng-content />patterns - Dynamic Components —
ViewContainerRef,NgComponentOutlet, lazy-loading, CDK Portals - Signals & Reactivity — Signals, computed, effects, view queries, and OnPush
- Standalone vs NgModules — Architecture comparison, migration, and interoperability
- Angular 20 Features — New APIs, advantages, disadvantages, and adoption guide
Quick Summary — Legacy vs Modern Syntax
Section titled “Quick Summary — Legacy vs Modern Syntax”| Feature | Legacy Syntax | Modern Syntax (Angular 18+) |
|---|---|---|
| Inputs | @Input() name: string | name = input<string>() |
| Required inputs | @Input({ required: true }) | name = input.required<string>() |
| Outputs | @Output() event = new EventEmitter() | event = output<T>() |
| Two-way binding | @Input() + @Output() pair | value = model<T>() |
| View queries | @ViewChild() / @ViewChildren() | viewChild() / viewChildren() |
| Content queries | @ContentChild() / @ContentChildren() | contentChild() / contentChildren() |
| Conditionals | *ngIf | @if |
| Loops | *ngFor | @for (item of items; track item.id) |
| Switch | [ngSwitch] | @switch |
| Standalone | standalone: true | Default (flag not needed) |
| Bootstrapping | bootstrapModule(AppModule) | bootstrapApplication(AppComponent, appConfig) |
| Lazy loading | loadChildren: () => Module | loadComponent: () => Component |
| Async data | Manual HTTP + subscribe | resource() / rxResource() |
| Zone | zone.js (implicit) | Zoneless with provideExperimentalZonelessChangeDetection() |
Best Practices
Section titled “Best Practices”- Keep components focused — Each component should have a single responsibility.
- Use signal inputs/outputs — Prefer
input(),output(), andmodel()over decorators. - Always use
OnPush— Better performance and predictable change detection. - Use descriptive selectors — Prefer
app-user-cardoverapp-uc. - Prefer external templates and styles — Better maintainability for larger components.
- Clean up resources — Use
DestroyReforngOnDestroyto free subscriptions/timers. - Leverage the CLI — Always use
ng generate componentfor consistent file structure. - Use
trackin@forloops — Always provide a tracking expression for performance. - Test dynamic components — Verify dynamically loaded components render correctly.
- Use content projection — Build flexible, reusable container components.
References
Section titled “References”- How to Build Your Own Angular Components: From Beginner to Advanced
- Mastering Angular Components in 2025
- How to Create Components Dynamically in Angular — 2026 Guide
- Angular Standalone Components vs Modules
- Angular Standalone Components: Simplifying Modern Angular Development
- The Power of Standalone Components and Signals in Angular 20
- Angular Official Documentation — Components
- Angular Signals Guide
- Angular Migration to Standalone