Created
June 9, 2017 16:13
-
-
Save xtianjohns/3e960c21fcb7af877cf64ca665a7e502 to your computer and use it in GitHub Desktop.
Using ngx-destroy
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
@Component({ | |
selector: 'my-component', | |
}) | |
export class MyComponent implements OnInit { | |
@NgDestroy() // decorate the property you want to use to track your destruction | |
private destroyed$: Observable<{}>; | |
ngOnInit(): void { | |
Observable.interval( 1000 ) | |
.takeUntil( this.destroyed$ ) // use the property in an operator | |
.subscribe( effect ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment