-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cancel pending requests if not visible any more #458
Comments
Yes, I have the same problem in some projects. I'll wait here |
Hi, this is currently not possible but I think it should be. The problem is that we need a reference to the fetcher when the component unmount. I will try to fix this in the next version. |
This should be possible to do if you can fetch the image by import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { HttpClientModule, HttpClient } from '@angular/common/http';
import { LazyLoadImageModule, IntersectionObserverHooks, Attributes } from 'ng-lazyload-image';
import { AppComponent } from './app.component';
class LazyLoadImageHooks extends IntersectionObserverHooks {
private http: HttpClient;
constructor(http: HttpClient) { // You can inject what ever service you want here
super();
this.http = http;
}
loadImage({ imagePath }: Attributes) {
return this.http.get(imagePath, {
responseType: 'blob',
}).pipe(map(blob => URL.createObjectURL(blob)));
}
}
@NgModule({
declarations: [AppComponent],
imports: [
BrowserModule,
HttpClientModule,
LazyLoadImageModule.forRoot(LazyLoadImageHooks, [HttpClient])
],
bootstrap: [AppComponent],
})
export class MyAppModule {} Let me know if something is unclear or if it doesn't work for you. The plan is to leave the beta channel in a couple of days. |
I have created a sandbox example here: https://codesandbox.io/s/lazy-load-image-with-httpclient-68785?file=/src/app/app.module.ts The easiest way to test it is to:
Take a look at the downloads. The images should be canceled or at least stop being downloaded (I don't know why they don't always get marked as canceled but you should see that the download has been stoped). |
Version |
Hi,
I have a page with a lot of thumbnails.
When user navigate to this page and leave before all images where loaded, then I want to cancel all the pending requests.
Is it possible to do it?
The text was updated successfully, but these errors were encountered: