Skip to content

Latest commit

 

History

History
32 lines (22 loc) · 540 Bytes

mw-destroy.service.md

File metadata and controls

32 lines (22 loc) · 540 Bytes

MwDestroyService

This class is used to reduce repeatable code responsible for unsubscribe process in components.

How to use

  1. Add service to providers in your component:
@Component({
   providers: [MwDestroyService],
})
  1. Inject service into constructor:
constructor(@Inject(MwDestroyService) destroy$: Observable<void>) {
}
  1. Add takeUntil(this.destroy$) to every direct subscription pipe:
this.form.valueChanges
  .pipe(
    takeUntil(this.destroy$),
  )
  .subscribe((): void => {...});