Skip to content

[lazyLoad]-Attribute won't resolved to "src"-Attribute #489

Open
@Swagtex

Description

@Swagtex

Hi there,

i have some trouble with lazy-loading on the SSR-Part.

Like the docs describes the [lazyLoad] attibute should be changed to src if the app is executed server-sided.
Browser-Part works fine. I'm facing this issue on two complete different environments. Results are the same.
To identify the problem i used a noscript browser extension. So the browser-part won't execute.

Versions:

Test environment:

  • Angular: 11.0.4
  • ng-lazyload-image: 9.1.0

Project environment:

  • Anuglar 10.2.0
  • ng-lazyload-image: 9.0.1

Reproduce:

ng new lazytest
ng add @nguniversal/express-engine
npm install ng-lazyload-image

Run the environment with:
npm run dev:ssr

app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { Injectable, NgModule } from '@angular/core';

import { AppComponent } from './app.component';
import { Attributes, IntersectionObserverHooks, LazyLoadImageModule, LAZYLOAD_IMAGE_HOOKS } from 'ng-lazyload-image';

@Injectable()
export class LazyLoadImageHooks extends IntersectionObserverHooks {
  skipLazyLoading(attributes: Attributes) {
    console.log("Hook called!"); //Only called on browser
    return true; //Should skip every lazy load
  }
}

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule.withServerTransition({ appId: 'serverApp' }),
    LazyLoadImageModule
  ],
  providers: [{ provide: LAZYLOAD_IMAGE_HOOKS, useClass: LazyLoadImageHooks }],
  bootstrap: [AppComponent]
})
export class AppModule { }

app.component.html

<h1>LazyLoad-Test</h1>
<div style="width: 100vw; height: 120vh;">
  Placeholder
</div>
<h2>Image should be right here</h2>
<img [lazyLoad]="'https://www.placecage.com/1000/1000'" />

What i'm doing wrong? I also tried to add the hook directly to the app.server.module.ts. Still no success. I'cant figure it out how to solve my issue. Maybe kind a related to #427.

Thanks in advance. Kind regards

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions