Bird
0
0

Which of the following is the correct way to unsubscribe from a subscription in Angular's ngOnDestroy method?

easy📝 Syntax Q12 of 15
Angular - RxJS and Observables Fundamentals
Which of the following is the correct way to unsubscribe from a subscription in Angular's ngOnDestroy method?
Athis.subscription.unsubscribe();
Bthis.subscription.stop();
Cthis.subscription.close();
Dthis.subscription.cancel();
Step-by-Step Solution
Solution:
  1. Step 1: Recall Subscription API

    The Subscription object has an unsubscribe() method to stop listening.
  2. Step 2: Identify correct method name

    Only unsubscribe() is valid; others do not exist on Subscription.
  3. Final Answer:

    this.subscription.unsubscribe(); -> Option A
  4. Quick Check:

    Use unsubscribe() to stop subscription = D [OK]
Quick Trick: Use unsubscribe() method to stop subscriptions [OK]
Common Mistakes:
MISTAKES
  • Using non-existent methods like stop() or cancel()
  • Forgetting to call unsubscribe() at all
  • Calling unsubscribe() outside ngOnDestroy

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes