Is there a way to unsubscribe to http call from angular service onDestroy hook.
P.S. I am aware of the rxjs 'take' operator or unsubscribing to service from component itself.
import { HttpClient } from "@angular/common/http";
import { Injectable, OnDestroy } from "@angular/core";
@Injectable()
export class SampleService implements OnDestroy {
constructor(private httpClient: HttpClient) {}
getSampleData() {
return this.httpClient.get("https://jsonplaceholder.typicode.com/todos/1");
}
ngOnDestroy(): void {
// automatically unsubscribe to service.
}
}