Recall & Review
beginner
What is service-based state management in Angular?
It is a way to keep and share data across components using Angular services. Services hold the state and provide methods to update or get data, so components stay in sync.
Click to reveal answer
beginner
Why use a service for state management instead of component properties?
Services allow multiple components to access and update the same data easily. Component properties are local and isolated, so sharing state between components is harder without services.
Click to reveal answer
intermediate
How do Angular services keep state persistent across components?
Angular services are singletons by default when provided in root. This means one instance is shared across the app, so the state inside the service stays consistent and accessible.
Click to reveal answer
intermediate
What Angular feature helps components react to state changes in a service?
Using RxJS Observables inside services lets components subscribe to state changes. When the service updates data, subscribers get notified and update their views automatically.
Click to reveal answer
beginner
Show a simple example of a service holding a counter state with increment method.
import { Injectable } from '@angular/core';
@Injectable({ providedIn: 'root' })
export class CounterService {
private count = 0;
getCount() { return this.count; }
increment() { this.count++; }
}
This service keeps count and lets components get or increase it.Click to reveal answer
What is the main benefit of using a service for state management in Angular?
✗ Incorrect
Services allow multiple components to share and update the same state easily.
How does Angular ensure a service is a singleton by default?
✗ Incorrect
Providing a service in root makes Angular create one shared instance for the whole app.
Which RxJS feature is commonly used in services to notify components about state changes?
✗ Incorrect
Observables let components subscribe and react to changes in service state.
What happens if you store state only in a component property?
✗ Incorrect
Component properties are local to that component and not shared.
Which Angular decorator is used to make a class a service?
✗ Incorrect
@Injectable() marks a class as a service that can be injected.
Explain how service-based state management works in Angular and why it is useful.
Think about how one place can keep data for many parts of your app.
You got /5 concepts.
Describe how you can notify Angular components about changes in service state.
Consider how a message system can tell others when data changes.
You got /4 concepts.