Open CrackerakiUA opened 3 years ago
Pls, can you make a PR ?
hey, sorry for late reply, I hope that you have fixed it, I used my clone of your repo, but if that can be solved on Universal level, that will make at least me turn back on your repo. Solution is:
import { PLATFORM_ID } from '@angular/core';
import { isPlatformServer } from '@angular/common';
...
constructor(private router: Router, @Inject(PLATFORM_ID) private platformId) {
if(isPlatformServer(this.platformId)){
this.document = {
querySelectorAll: ()=>{},
addEventListener: ()=>{},
removeEventListener: ()=>{},
documentElement: {},
body: {},
};
}else{
this.document = document;
}
}
And similar for any other global javascript variable. I know also that there is better solution of this with providers, but this is my workout.
Hello, is there any update this this issue?
In universal, on node.js back-end we don't have document and window variables, they are undefined. This make below error on universal.
It can be fixed by setting those variables if they are undefined on below lines https://github.com/mzuccaroli/angular-google-tag-manager/blob/master/projects/angular-google-tag-manager/src/lib/angular-google-tag-manager.service.ts#L12 https://github.com/mzuccaroli/angular-google-tag-manager/blob/master/projects/angular-google-tag-manager/src/lib/angular-google-tag-manager.service.ts#L15