DEV Community

Discussion on: This Angular helper function has saved me from memory leaks for 4 years

Collapse
 
zhhb profile image
Ten

why do like this:

destroy = new Subject()
// some where you do subscribe
someObservable.pipe(takeUnitl(this.destroy)).subscribe(....)

ngOnDestroy(){
this.destroy.next();
this.destroy.complate();
}
Collapse
 
gempain profile image
Geoffroy Empain

That's a nice way to do it as well :)