Component State
Introduction
Section titled “Introduction”Component state is the simplest form of state management — state that’s only relevant to one component and its children.
Example
Section titled “Example”@Component({ template: ` <button (click)="toggle()">{{ isOpen ? 'Close' : 'Open' }}</button> `})export class DropdownComponent { isOpen = false; toggle() { this.isOpen = !this.isOpen; }}When to Use
Section titled “When to Use”- UI state (dropdowns, modals, toggles)
- Form state
- Any state scoped to a single component
Summary
Section titled “Summary”Keep state as local as possible. Only elevate state when multiple components need it.”