ngx-progressive-image-loader icon indicating copy to clipboard operation
ngx-progressive-image-loader copied to clipboard

Universal issue

Open Ismaestro opened this issue 6 years ago • 12 comments

Hello again 😄!

I have this error while serving the app built with Angular Universal:

Error: StaticInjectorError(AppServerModule)[ProgressiveImageDirective -> InjectionToken WindowToken]: 
  StaticInjectorError(Platform: core)[ProgressiveImageDirective -> InjectionToken WindowToken]: 
    NullInjectorError: No provider for InjectionToken WindowToken!

any ideas?? I'm importing the last version in beta (7).

Ismaestro avatar Apr 17 '19 18:04 Ismaestro

Fixed with this:

  isBrowser: boolean;

  constructor(@Inject(PLATFORM_ID) private platformId: Object) {
    if (isPlatformBrowser(this.platformId)) {
      this.isBrowser = true;
    }
  }
  <ng-container *ngIf="isBrowser">
    <ngx-progressive-image-loader
      [filter]="'blur(3px) drop-shadow(0 0 0.75rem crimson)'"
      [placeholderImageSrc]="hero.avatarBlurredUrl">
      <img (click)="seeHeroDetails(hero)" src="{{hero.avatarUrl}}" alt="" ngxProgressiveImage />
    </ngx-progressive-image-loader>
  </ng-container>

Maybe you should add some documentation on this or a demo... Finally working here :)

Ismaestro avatar Apr 17 '19 22:04 Ismaestro

I thought I had a demo? but thanks! This is still work in process. I will try to make it better and welcome to make a pull request.

maxisam avatar Apr 18 '19 03:04 maxisam

Could you try 4.0.0-beta.9? you don't need <ng-container *ngIf="isBrowser"> anymore in theory.

maxisam avatar Apr 18 '19 03:04 maxisam

Done, and yes, it's working as expected.

Thanks!!

Ismaestro avatar Apr 18 '19 14:04 Ismaestro

Thank you! Btw, I liked your project from long times ago. Thank you for creating that project.

maxisam avatar Apr 18 '19 15:04 maxisam

@Ismaestro also could you try 4.0.0-beta.12. I think it will help on things like some images are not loaded properly

maxisam avatar Apr 18 '19 16:04 maxisam

With that version while serving the app with ssr, I got this error:

> [email protected] serve:ssr /Users/iramos/WebstormProjects/angular7-example-app
> node dist/server

Node server listening on http://localhost:4000
/Users/iramos/WebstormProjects/angular7-example-app/dist/server.js:344
                        throw error;
                        ^

TypeError: Cannot read property 'src' of undefined
    at loadImage (/Users/iramos/WebstormProjects/angular7-example-app/dist/server.js:279342:27)
    at ProgressiveImageDirective.ngOnInit (/Users/iramos/WebstormProjects/angular7-example-app/dist/server.js:279694:13)
    at checkAndUpdateDirectiveInline (/Users/iramos/WebstormProjects/angular7-example-app/dist/server.js:26202:19)
    at checkAndUpdateNodeInline (/Users/iramos/WebstormProjects/angular7-example-app/dist/server.js:27466:20)
    at checkAndUpdateNode (/Users/iramos/WebstormProjects/angular7-example-app/dist/server.js:27428:16)

Serving the app with JIT goes fine.

:)

Ismaestro avatar Apr 18 '19 19:04 Ismaestro

Weird. That doesn't make any sense. There are only 2 changes between 9 and 12, https://github.com/maxisam/ngx-progressive-image-loader/pull/11/commits/819dae7afbf8ce1963e3a054685d68e2c3116776 and https://github.com/maxisam/ngx-progressive-image-loader/pull/11/commits/717c266cd5e1815e1a037dcf9f0f2d302b0af459 I don't understand how could it work on 9 but not 12

maxisam avatar Apr 18 '19 19:04 maxisam

Yup so weird. You can reproduce the error just clone my project, upgrade the version, npm run build:ssr and npm run serve:ssr. You will see the error...

Ismaestro avatar Apr 18 '19 20:04 Ismaestro

I will try it sometime this week.

maxisam avatar Apr 18 '19 21:04 maxisam

I've also encountered an error while running with universal app

export '_window' (imported as 'i11') was not found in 'ngx-window-token'

"ngx-progressive-image-loader": "^3.0.2", "ngx-window-token": "^2.0.1", "tslib": "^1.10.0

Tried to recreate this with just angular and works fine. Let me know if I missed something

rassrig avatar Jan 30 '20 09:01 rassrig

please try the latest beta version. 4.0.0-beta.15. I used it on production for a while already.

maxisam avatar Jan 30 '20 14:01 maxisam