G
G
Ghoulll2021-05-01 15:08:11
Angular
Ghoulll, 2021-05-01 15:08:11

How to properly unsubscribe from subscriptions in Angular?

Do I need to unsubscribe from a subscription to a subscription? Or can you get away with the 1st unsubscribe?

this.authService.getUuid()
      .pipe(untilDestroyed(this)) // 1-я отписка
      .subscribe(phraseFromServer => {
        this.authService.sendPhraseToPlugin()
          .pipe(untilDestroyed(this)) // 2-я отписка
          .subscribe(signedCert => {
          this.signedCert = signedCert;
        }
      }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ruslan Lopatin, 2021-05-01
@Ghoulll

Better like this:

this.authService.getUuid().pipe(
  switchMap(phraseFromServer => this.authService.sendPhraseToPlugin()),
  untilDestroyed(this),
).subscribe(signedCert => {
  this.signedCert = signedCert;
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question