Let’s say i have this component, in which the users can call getData()
function multiple times, how to manage this correctly? as i understand this will cause memory leaks because it’s creating a new subscription each getData()
function call. Thanks in advance.
export class AnalyticsComponent {
constructor(
private http: HttpClient
) { }
getData() {
const url = `${environment.apiUrl}/protected`;
this.http.get(url).pipe(
map(response => console.log(response)),
catchError(async error => console.error(error))
).subscribe();
}
}