ng-toolkit
ng-toolkit copied to clipboard
@ng-toolkit/universal window.location is undefined
I'm submitting a...
[ ] Bug report
[x] Feature request
[ ] Documentation issue or request
In package
[ ] @ng-toolkit/init
[ ] @ng-toolkit/serverless
[x] @ng-toolkit/universal
[ ] @ng-toolkit/pwa
[ ] @ng-toolkit/firebug
Current behavior
window.location
is returning undefined
during server-side rendering. As I currently understand this is not possible by injecting WINDOW
from 'ng-toolkit/universal'. I found a few possible solutions online:
- https://stackoverflow.com/questions/56004723/angular-7-how-can-i-get-the-complete-url-of-the-current-page
- https://stackoverflow.com/questions/36222845/get-domain-name-for-service-in-angular2
- https://medium.com/the-innovation/angular-universal-referenceerror-window-is-not-defined-f0ed140e3210
But none of them worked for me.
Expected behavior
I need window.location
to return all the usual data when executed in a browser.
Minimal reproduction of the problem with instructions
constructor(@Inject(WINDOW) private window: Window) {
const { host } = this.window.location;
console.log(host);
}
Environment
- Angular version: 8.3.8
- Node version: 10.19.0
- Platform: Ubuntu 20.04