Back to results for “Dependency injection”
Angular › State Management

What is state management in an Angular app?

Beginner

Answer

State management refers to how an app organizes and shares data that changes over time, such as the current logged in user, items in a shopping cart, or a form's values. Small apps often manage this using a simple service combined with signals, while larger apps sometimes reach for a dedicated library like NgRx to keep things organized.
@Injectable({ providedIn: 'root' })
export class CartService {
  items = signal<Item[]>([]);

  addItem(item: Item) {
    this.items.update((current) => [...current, item]);
  }
}
Real-world example A small online store manages its shopping cart entirely with a signal based service, letting any component that injects the service read and react to the current cart contents automatically.

Common follow-ups: At what point does an app typically need more than just a simple service for managing its data?;What is the difference between local component state and shared application state?