Loading

Quipoin Menu

Learn • Practice • Grow

angular / Using Services for Data Sharing
mcq
Direction: Choose the correct option

Q1.

How can multiple components share data using a service?
A. Using global variables
B. Using cookies
C. Using a service with properties and methods
D. Using local storage
Direction: Choose the correct option

Q2.

How do you make a service observable for data changes?
A. Using callbacks
B. Using RxJS Subject or BehaviorSubject
C. Using Promises
D. Using events
Direction: Choose the correct option

Q3.

What is the difference between Subject and BehaviorSubject?
A. Both are the same
B. Subject emits historical values
C. BehaviorSubject requires an initial value and emits the current value to new subscribers
D. Subject has no initial value
Direction: Choose the correct option

Q4.

How does a component subscribe to a service's observable?
A. Using `.subscribe()` method
B. Both A and B
C. Using `async` pipe in template
D. Using `@Input`
Direction: Choose the correct option

Q5.

What should you do with subscriptions in a component?
A. Unsubscribe in ngOnInit
B. Unsubscribe in ngOnDestroy to prevent memory leaks
C. Nothing, they auto-clean
D. Only unsubscribe if using async pipe
Direction: Choose the correct option

Q6.

What is a ReplaySubject?
A. An Subject that can send old values to new subscribers
B. A Subject that repeats
C. A Subject that records
D. A Subject that replays
Direction: Choose the correct option

Q7.

How do you expose an observable from a service without allowing emits?
A. Return a new Subject
B. Return `asObservable()` of the Subject
C. Return a Promise
D. Return the Subject directly
Direction: Choose the correct option

Q8.

What is the purpose of a service in state management?
A. To handle routing
B. To render views
C. To hold and manage application state
D. To make HTTP calls
Direction: Choose the correct option

Q9.

Can a service have multiple instances?
A. Yes, if provided at component level
B. Only if `providedIn: 'root'`
C. Only in modules
D. No, always singleton
Direction: Choose the correct option

Q10.

What is the best practice for unsubscribing?
A. Never unsubscribe
B. Unsubscribe in ngOnInit
C. Unsubscribe in constructor
D. Using `takeUntil` pattern or `async` pipe