Is it possible to automatically unsubscribe from an http call in an Angular service using the ngOnDestroy hook?
Just to note, I am already familiar with using the rxjs 'take' operator or manually unsubscribing from the service within the 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 {
// handle automatic unsubscription here
}
}