Last active
February 4, 2020 08:46
-
-
Save kaplan81/e48df2dac23a43fc7384258056ac7c3a to your computer and use it in GitHub Desktop.
This file contains hidden or 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 { ChangeDetectionStrategy, Component, OnDestroy, OnInit } from '@angular/core'; | |
import { interval, Observable, Subject, Subscription } from 'rxjs'; | |
import { takeUntil, tap } from 'rxjs/operators'; | |
@Component({ | |
changeDetection: ChangeDetectionStrategy.OnPush, | |
templateUrl: './boilerplate.component.html', | |
}) | |
export class BoilerplateComponent implements OnInit, OnDestroy { | |
destroyed$ = new Subject<void>(); | |
observable$: Observable<number> = interval(1000); | |
subscription$$: Subscription; | |
ngOnInit(): void { | |
this.subscription$$ = this.observable$ | |
.pipe(tap(console.log), takeUntil(this.destroyed$)) | |
.subscribe(); | |
} | |
ngOnDestroy(): void { | |
this.destroyed$.next(); | |
// Any extra actions: | |
console.log('this.subscription$$.closed in ngOnDestroy:::', this.subscription$$.closed); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment