Last active
February 4, 2020 08:46
-
-
Save kaplan81/2a25472f5b139746a15eb4aedddef197 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, Subscription } from 'rxjs'; | |
import { takeUntil, tap } from 'rxjs/operators'; | |
import { ondestroy } from '../_app/decorators/ondestroy.decorator'; | |
@Component({ | |
changeDetection: ChangeDetectionStrategy.OnPush, | |
templateUrl: './decorator.component.html', | |
}) | |
export class DecoratorComponent implements OnInit, OnDestroy { | |
observable$: Observable<number> = interval(1000); | |
subscription$$: Subscription; | |
ngOnInit(): void { | |
this.subscription$$ = this.observable$ | |
.pipe(tap(console.log), takeUntil((this as any).destroyed$)) | |
.subscribe(); | |
} | |
@ondestroy() | |
ngOnDestroy(): void { | |
// 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