Bird
0
0

Which of the following is the correct syntax to subscribe to an Observable named data$ inside ngOnInit?

easy📝 Syntax Q3 of 15
Angular - RxJS and Observables Fundamentals
Which of the following is the correct syntax to subscribe to an Observable named data$ inside ngOnInit?
Athis.data$.subscribe(value => { this.data = value; });
Bthis.data$.subscribe = value => { this.data = value; };
Csubscribe(this.data$, value => this.data = value);
Dthis.data$.subscribe(value) { this.data = value; };
Step-by-Step Solution
Solution:
  1. Step 1: Recall Observable subscription syntax

    Use observable.subscribe(callback) to listen to emitted values.
  2. Step 2: Check each option for correct syntax

    this.data$.subscribe(value => { this.data = value; }); correctly calls subscribe method with an arrow function callback.
  3. Final Answer:

    this.data$.subscribe(value => { this.data = value; }); -> Option A
  4. Quick Check:

    Subscription syntax = A [OK]
Quick Trick: Use observable.subscribe(callback) with arrow function [OK]
Common Mistakes:
MISTAKES
  • Assigning subscribe instead of calling it
  • Using subscribe as a standalone function
  • Incorrect function syntax inside subscribe

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes