Basic State Management
Component state, services state, BehaviorSubject, state patterns, stateful vs stateless components, shared state
1What is the simplest way to declare local state in an Angular component?
What is the simplest way to declare local state in an Angular component?
Answer
Declaring a class property directly in the component is the simplest method for managing local state. This approach is perfect for data that is only used by this component and doesn't need to be shared. Properties are automatically accessible in the template and can be modified directly.
2What is the main characteristic of a stateless component?
What is the main characteristic of a stateless component?
Answer
A stateless component has no internal state and relies solely on @Input to receive its data. These components are purely presentational and emit events via @Output to communicate with their parent. This architecture improves reusability and facilitates testing.
3Why use a BehaviorSubject instead of a Subject for state management?
Why use a BehaviorSubject instead of a Subject for state management?
Answer
BehaviorSubject always stores the last emitted value and immediately sends it to new subscribers. This characteristic is essential for state management because components need access to the current state as soon as they initialize, without waiting for a new emission. Subject keeps no value and new subscribers only receive future emissions.
What is the best practice for exposing state managed by an Angular service?
How to share state between multiple components that are not related by a parent-child relationship?
+17 interview questions
Other Angular interview topics
TypeScript Basics
TypeScript Advanced
Angular Fundamentals
Components & Lifecycle
Services & Dependency Injection
Angular Modules Organization
Angular CLI
Directives & Pipes
Routing & Navigation
Reactive Forms
Template-driven Forms
RxJS Fundamentals
RxJS Operators
HttpClient & API Calls
Change Detection
Angular Signals
Standalone Components
Angular Unit Testing
End-to-End Testing
Build & Optimization
NgRx Fundamentals
NgRx Advanced
Angular Architecture
Performance Optimization
Security & Best Practices
Advanced RxJS Patterns
Angular Universal & SSR
Angular Micro-frontends
Master Angular for your next interview
Access all questions, flashcards, technical tests, code review exercises and interview simulators.
Start for free