pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://angular.dev/assets/context/angular-20.mdc

handle it safely. ## Angular Best Practices * **Standalone Components:** Always use standalone components, directives, and pipes. Avoid using `NgModules` for new features or refactoring existing ones. * **Implicit Standalone:** When creating standalone components, you do not need to explicitly set `standalone: true` inside the `@Component`, `@Directive` and `@Pipe` decorators, as it is implied by default. * **Bad:** ```typescript @Component({ standalone: true, // ... }) export class MyComponent {} ``` * **Good:** ```typescript @Component({ // `standalone: true` is implied // ... }) export class MyComponent {} ``` * **Signals for State Management:** Utilize Angular Signals for reactive state management within components and services. * **Lazy Loading:** Implement lazy loading for feature routes to improve initial load times of your application. * **NgOptimizedImage:** Use `NgOptimizedImage` for all static images to automatically optimize image loading and performance. * **Host bindings:** Do NOT use the `@HostBinding` and `@HostListener` decorators. Put host bindings inside the `host` object of the `@Component` or `@Directive` decorator instead. ## Components * **Single Responsibility:** Keep components small, focused, and responsible for a single piece of functionality. * **`input()` and `output()` Functions:** Prefer `input()` and `output()` functions over the `@Input()` and `@Output()` decorators for defining component inputs and outputs. * **Old Decorator Syntax:** ```typescript @Input() userId!: string; @Output() userSelected = new EventEmitter(); ``` * **New Function Syntax:** ```typescript import { input, output } from '@angular/core'; // ... userId = input(''); userSelected = output(); ``` * **`computed()` for Derived State:** Use the `computed()` function from `@angular/core` for derived state based on signals. * **Inline Templates:** Prefer inline templates (template: `...`) for small components to keep related code together. For larger templates, use external HTML files. * **Reactive Forms:** Prefer Reactive forms over Template-driven forms for complex forms, validation, and dynamic controls due to their explicit, immutable, and synchronous nature. * **No `ngClass` / `NgClass`:** Do not use the `ngClass` directive. Instead, use native `class` bindings for conditional styling. * **Bad:** ```html
``` * **Good:** ```html
``` * **No `ngStyle` / `NgStyle`:** Do not use the `ngStyle` directive. Instead, use native `style` bindings for conditional inline styles. * **Bad:** ```html
``` * **Good:** ```html
``` ## State Management * **Signals for Local State:** Use signals for managing local component state. * **`computed()` for Derived State:** Leverage `computed()` for any state that can be derived from other signals. * **Pure and Predictable Transformations:** Ensure state transformations are pure functions (no side effects) and predictable. * **Signal value updates:** Do NOT use `mutate` on signals, use `update` or `set` instead. ## Templates * **Simple Templates:** Keep templates as simple as possible, avoiding complex logic directly in the template. Delegate complex logic to the component's TypeScript code. * **Native Control Flow:** Use the new built-in control flow syntax (`@if`, `@for`, `@switch`) instead of the older structural directives (`*ngIf`, `*ngFor`, `*ngSwitch`). * **Old Syntax:** ```html
Content
{{ item }}
``` * **New Syntax:** ```html @if (isVisible) {
Content
} @for (item of items; track item.id) {
{{ item }}
} ``` * **Async Pipe:** Use the `async` pipe to handle observables in templates. This automatically subscribes and unsubscribes, preventing memory leaks. ## Services * **Single Responsibility:** Design services around a single, well-defined responsibility. * **`providedIn: 'root'`:** Use the `providedIn: 'root'` option when declaring injectable services to ensure they are singletons and tree-shakable. * **`inject()` Function:** Prefer the `inject()` function over constructor injection when injecting dependencies, especially within `provide` functions, `computed` properties, or outside of constructor context. * **Old Constructor Injection:** ```typescript constructor(private myService: MyService) {} ``` * **New `inject()` Function:** ```typescript import { inject } from '@angular/core'; export class MyComponent { private myService = inject(MyService); // ... } ``` pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy