Created
December 29, 2020 00:28
-
-
Save blove/52eded129083a43b07b32c70884b80e5 to your computer and use it in GitHub Desktop.
Angular BaseComponent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Directive, OnDestroy } from '@angular/core'; | |
import { Subject } from 'rxjs'; | |
@Directive() | |
// tslint:disable-next-line:directive-class-suffix | |
export abstract class BaseComponent implements OnDestroy { | |
private destroy$: Subject<void> | null = null; | |
get destroy() { | |
if (!this.destroy$) { | |
this.destroy$ = new Subject(); | |
} | |
return this.destroy$.asObservable(); | |
} | |
ngOnDestroy() { | |
if (this.destroy$) { | |
this.destroy$.next(); | |
this.destroy$.complete(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment