0

I'm looking at this code snippet that uses untilDestroyed:

      this.control.valueChanges.pipe(untilDestroyed(this)).subscribe(c => {
        this.update.emit(c);
      });
    }

Does Angular automatically unsubscribe the FormControl.valueChanges observable on component destruction, or do we need the operator?

Part of the reason I ask is that my understanding is that Angular unsubscribes Observables used in template expressions automatically, so I thought perhaps it might have a "Magic" way of doing it for FormControl instances as well?

Ole
  • 36,095
  • 47
  • 151
  • 295
  • 1
    Possible duplicate of [Angular 2 - Does subscribing to FormControl's valueChanges need an unsubscribe?](https://stackoverflow.com/questions/41364078/angular-2-does-subscribing-to-formcontrols-valuechanges-need-an-unsubscribe) – ggradnig Sep 06 '18 at 08:13

1 Answers1

1

You should unsubscribe in ngOnDestroy component callback.

Since stream is never closed, subscription will stay.

Antoniossss
  • 28,922
  • 5
  • 49
  • 91