Skip to content

Instantly share code, notes, and snippets.

@trubachoff
Created October 18, 2021 12:12
Show Gist options
  • Save trubachoff/960510a1948d411b45909474a3eec11c to your computer and use it in GitHub Desktop.
Save trubachoff/960510a1948d411b45909474a3eec11c to your computer and use it in GitHub Desktop.
Angular abstract onDestroy calss
import { Subject } from 'rxjs';
import { Injectable, OnDestroy } from '@angular/core';
@Injectable()
export class AbstractBasicComponent implements OnDestroy {
protected destroy$ = new Subject();
public ngOnDestroy(): void {
this.destroy$.next();
this.destroy$.complete();
}
@trubachoff
Copy link
Author

class Example extends AbstractBasicComponent
// ...
observable$.pipe(
  takeUntil(this.destroy$)
).subscribe()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment