Skip to content

Instantly share code, notes, and snippets.

@xtianjohns
Created June 9, 2017 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xtianjohns/3e960c21fcb7af877cf64ca665a7e502 to your computer and use it in GitHub Desktop.
Save xtianjohns/3e960c21fcb7af877cf64ca665a7e502 to your computer and use it in GitHub Desktop.
Using ngx-destroy
@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