When I make an http call and subscribe to it, I notice that even after closing the component, the subscription is not destroyed and continues to run once. Shouldn't the http subscriptions be automatically removed when a component is destroyed?
Below is the method that is being called:
getCubes() {
this.loading_cubes = true;
this.urlService.getCubes().subscribe({
next:(data:any) => {
if (data.success) {
this.cubesDataArray = data.data[0].response;
} else {
Swal.fire(data.status_message);
console.log(data.error_message);
}
this.loading_cubes = false;
},
error:(err:any) => {
console.log(err);
Swal.fire('Opps an error occured');
this.loading_cubes = false;
}
});
}
And here's the service function that returns the http observable:
getCubes() {
return this.http.get(this.serviceURL + '/cubes', this.options);
}
This issue is not isolated to just one case—it happens with every request I make. The pop-ups keep appearing even after I've closed the component.
Could it possibly be related to a setting in the tsconfig.json file?