This class is used to reduce repeatable code responsible for unsubscribe process in components.
- Add service to providers in your component:
@Component({
providers: [MwDestroyService],
})
- Inject service into constructor:
constructor(@Inject(MwDestroyService) destroy$: Observable<void>) {
}
- Add
takeUntil(this.destroy$)
to every direct subscription pipe:
this.form.valueChanges
.pipe(
takeUntil(this.destroy$),
)
.subscribe((): void => {...});