Skip to content
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

Angular universal support (need reopen) #176

Closed
sokolandia opened this issue Apr 5, 2019 · 12 comments
Closed

Angular universal support (need reopen) #176

sokolandia opened this issue Apr 5, 2019 · 12 comments

Comments

@sokolandia
Copy link

Server side rendering still gives an error in the latest version of the library:
ERROR { Error: StaticInjectorError(AppServerModule)[InjectionToken WindowToken]: StaticInjectorError(Platform: core)[InjectionToken WindowToken]: NullInjectorError: No provider for InjectionToken WindowToken!
@angular/cli: 7.2.4
ngx-clipboard: 12.0.0

@maxisam
Copy link
Owner

maxisam commented Apr 5, 2019

what is your angular version

@sokolandia
Copy link
Author

Angular CLI: 7.2.4
Node: 9.5.0
OS: linux x64
Angular: 7.2.11
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, platform-server, router

Package Version

@angular-devkit/architect 0.10.7
@angular-devkit/build-angular 0.10.7
@angular-devkit/build-optimizer 0.10.7
@angular-devkit/build-webpack 0.10.7
@angular-devkit/core 7.0.7
@angular-devkit/schematics 7.2.4
@angular/cdk 7.3.6
@angular/cli 7.2.4
@angular/material 7.3.6
@ngtools/webpack 7.0.7
@schematics/angular 7.2.4
@schematics/update 0.12.4
rxjs 6.4.0
typescript 3.2.4
webpack 4.29.6

@maxisam
Copy link
Owner

maxisam commented Apr 8, 2019

Can you check your package lock file like yarn.lock and search for ngx windows token and see if the version is 2 and above?

@sokolandia
Copy link
Author

"ngx-window-token": {
      "version": "2.0.1",   
      "resolved": "https://registry.npmjs.org/ngx-window-token/-/ngx-window-token-2.0.1.tgz",   
      "integrity": "sha512-rvqdqJEfnWXQFU5fyfYt06E10tR/UtFOYdF3QebfcOh5VIJhnTKiprX8e4B9OrX7WEVFm9BT8uV72xXcEgsaKA==",   
      "requires": {
        "tslib": "1.9.3"
      }
    },
"ngx-clipboard": {
      "version": "12.0.0",
      "resolved": "https://registry.npmjs.org/ngx-clipboard/-/ngx-clipboard-12.0.0.tgz",
      "integrity": "sha512-uN5KMNIiRT7uVHfJ5lgDSb7AvfkHvMrPjIKSaptWFl+z9AsMQq7/5IW6hfxx11AUPXY/yfoP4PWHsJ9KBwfv+g==",
      "requires": {
        "ngx-window-token": "2.0.1",
        "tslib": "1.9.3"
      }
    }

@sokolandia
Copy link
Author

This is the code from ngx-window-token
export const WINDOW = new InjectionToken<Window>( 'WindowToken', typeof window !== 'undefined' && window.document ? { providedIn: 'root', factory: () => window } : undefined );

It doesn't seem right, does it? I know it's opensource and all but common

@maxisam
Copy link
Owner

maxisam commented Apr 12, 2019

Which part?

@sokolandia
Copy link
Author

If there is no window new InjectionToken() will get undefined as a second parameter which is invalid. For it to work it has to get { providedIn: 'root', factory: () => ... } as a second parameter regardless

@maxisam
Copy link
Owner

maxisam commented Apr 16, 2019

@sokolandia I think you are correct. Or I should change it to be optional at here

constructor(@Inject(DOCUMENT) public document: any, @Inject(WINDOW) private window: any) {}

@Optional() @Inject(WINDOW) private window: any

@maxisam
Copy link
Owner

maxisam commented Apr 16, 2019

please try [email protected]

@sokolandia
Copy link
Author

dude just drop that library and replace it with
export const WINDOW = new InjectionToken('window', { providedIn: 'root', factory: () => typeof window !== 'undefined' ? window : null });

@maxisam
Copy link
Owner

maxisam commented Apr 18, 2019

Did you try it?

@maxisam
Copy link
Owner

maxisam commented Apr 18, 2019

It should be fixed according to the similar issue here. maxisam/ngx-progressive-image-loader#12

@maxisam maxisam closed this as completed Apr 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants