K
K
Konstantin2020-04-18 17:12:17
Angular
Konstantin, 2020-04-18 17:12:17

How can I improve my Subscription unsubscribe?

The component has several subscriptions from which I unsubscribe in destruction:

ngOnDestroy() {
   if (this.orderDefinitionRequestSubscription) {
      this.orderDefinitionRequestSubscription.unsubscribe();
    }

    if (this.createOrderSubscription) {
      this.createOrderSubscription.unsubscribe();
    }

    if (this.createBlockSubscription) {
      this.createBlockSubscription.unsubscribe();
    }

    if (this.orderVersionsSubscription) {
      this.orderVersionsSubscription.unsubscribe();
    }
}


How can this code be improved and avoid duplication?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Brezhnev, 2020-04-18
@Junart1

https://medium.com/ngx/why-do-you-need-unsubscribe...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question