Skip to content

Instantly share code, notes, and snippets.

@juanmendes
Created October 18, 2019 14:54
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 juanmendes/098cda61c1d5cf7715a557a00dddc7cc to your computer and use it in GitHub Desktop.
Save juanmendes/098cda61c1d5cf7715a557a00dddc7cc to your computer and use it in GitHub Desktop.
Simple unsubscribing
@Component({})
class NonLeakyComponent implements OnDestroy {
private subscriptions: Subscription[];
ngOnInit() {
const myTimer = timer(1,1);
this.subscriptions.push(myTimer.subscribe(
() => console.log("timer called")
));
}
ngOnDestroy() {
this.subscriptions.forEach(s => s.unsubscribe());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment