-
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
Set global window replacement #323
Comments
I really see a use case for this. Not only for scrollTarget but also to make it possible to create a custom I guess the best way to support this is to create a I will accept a PR if you are up to the task @joshhills and I will help you out in any way I can. |
Ah, I had always wondered what |
Update Original Hi, I'm running into the same problem. I use Angular Material 2 and had a When I do I wonder if there is an option to opt out the trigger-by-scrolling for deciding the timing of loading image. But then this might no longer be "lazy" loading images. Currently I'm considering some alternative solutions like load in images one by one at a time instead of concurrently, to mitigate the lag effect on the web page. I understand this is out of scope of ng-lazyload-image though. But using some libraries like Angular Material 2 along with |
Hi @joshhills, This should be possible in 2.1.0. If you fist define import { fromEvent } from 'rxjs';
function getObservable() {
return fromEvent(document.getElementById("MY-COMPONENT"), 'scroll');
} And then give it to @NgModule({
declarations: [ AppComponent ],
imports: [
BrowserModule,
LazyLoadImageModule.forRoot({ getObservable })
],
bootstrap: [ AppComponent ]
}) Or even better. Using import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { LazyLoadImageModule, intersectionObserverPreset } from 'ng-lazyload-image';
import { AppComponent } from './app.component';
@NgModule({
declarations: [ AppComponent ],
imports: [
BrowserModule,
LazyLoadImageModule.forRoot({
preset: intersectionObserverPreset
})
],
bootstrap: [ AppComponent ]
})
export class MyAppModule {} Let me know if you run into any problems. |
This is a feature request - I'm happy to try to contribute but I'm not entirely sure where best to put it.
There have been a few issues you've answered already concerning the idea that somebody mightn't be using the
window
as a scroll but rather some sort of custom nested container dependent on their framework.I'm using a
div
in Angular2 that is smaller than the window and hasoverflow-y: scroll
; ergo, the events do not bubble up. The images inside thediv
are furthermore within child components. I know you can passscrollTarget
, however that would mean that for every image in my application, its parent component would have to go get a reference to that one scroll container to pass in. Creating a service to return a reference to that one component also seems obtuse.I've temporarily replaced line 49 in the directive script with:
scrollObservable = scroll_listener_1.getScrollListener(_this.scrollTarget || document.getElementById("MY-COMPONENT"));
- awful, I know. I think it would be better to be able to tell the plugin globally to use a different element to the window as a fallback.Thoughts? 😄
The text was updated successfully, but these errors were encountered: