Skip to content

Instantly share code, notes, and snippets.

@alvachien
Created January 11, 2018 05:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alvachien/eb9f99fac7fbbe4c15b67fc07bbbd568 to your computer and use it in GitHub Desktop.
Save alvachien/eb9f99fac7fbbe4c15b67fc07bbbd568 to your computer and use it in GitHub Desktop.
class myComponent {
private destroyed$: ReplaySubject<boolean> = new ReplaySubject(1);
constructor(
private serviceA: ServiceA,
private serviceB: ServiceB,
private serviceC: ServiceC) {}
ngOnInit() {
this.serviceA
.takeUntil(this.destroyed$)
.subscribe(...);
this.serviceB
.takeUntil(this.destroyed$)
.subscribe(...);
this.serviceC
.takeUntil(this.destroyed$)
.subscribe(...);
}
ngOnDestroy() {
this.destroyed$.next(true);
this.destroyed$.complete();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment