onDestroy() is a lifecycle hook that is called when a directive, pipe or service is destroyed.When an Angular component is destroyed, the ngOnDestroy life cycle method is called so we can clean up long-running tasks or unsubscribe from any RxJS Observables. Angular Services also have an ngOnDestroy method, just like Angular components. This lifecycle can be helpful when we create and destroy services that need to run some cleanup work when the component is destroyed.ngOnDestroy() {this.data.unsubscribe(); }