Skip to content

Instantly share code, notes, and snippets.

@NetanelBasal
Last active May 19, 2022 08:42
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 NetanelBasal/272bf890fbfe1aedd4584ed7ed53a98d to your computer and use it in GitHub Desktop.
Save NetanelBasal/272bf890fbfe1aedd4584ed7ed53a98d to your computer and use it in GitHub Desktop.
export function untilDestroyed() {
const subject = new Subject<void>();
const viewRef = inject(ChangeDetectorRef) as ViewRef;
viewRef.onDestroy(() => {
subject.next();
subject.complete()
});
return takeUntil(subject.asObservable())
}
@Component({
selector: 'app-todo-page',
templateUrl: './todo-page.component.html'
})
export class TodoPageComponent {
destroy$ = untilDestroyed();
ngOnInit() {
interval(1000).pipe(
this.destroy$
).subscribe(console.log)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment