Open yalesnikov opened 4 years ago
Thanks! Is a bug for universal. I try to fix this.
Hello, I solved this problem to add that:
// START fix for dom manipulations
// This code was copied from stackOverFlow and don't analyzed
const domino = require('domino')
const fs = require('fs')
const path = require('path')
const template = fs.readFileSync('dist/browser/index.html').toString()
const win = domino.createWindow(template)
global['window'] = win
global['document'] = win.document
global['DOMTokenList'] = win.DOMTokenList
global['Node'] = win.Node
global['Text'] = win.Text
global['HTMLElement'] = win.HTMLElement
global['navigator'] = win.navigator
// END fir for dom manipulations
And also I used 'isBrowser' in my components where I use reach goal.
But I think that is not true solution for everyone. Maybe you should to add some conditions that general module doesn't start if it is server?
Sorry for my bad English
Hello,
Many thanks for providing this plugin! I currently encounter the same issue and it seems the bug is open since a few years now. Are there any plans for a fix?
In the meanwhile I used the following (ugly) workaround to inject the service conditionally only on client side code. Pre-rendered file generation works fine with Angular Universal by using:
export class AppComponent implements OnInit {
private ym: NgxMetrikaService;
constructor(private injector: Injector, @Inject(PLATFORM_ID) private platformId: Object) {
// Client only code. Workaround for Angular Universal
if (isPlatformBrowser(this.platformId)) {
this.ym = <NgxMetrikaService>this.injector.get(NgxMetrikaService);
}
}
I hope it helps.
Cheers.
Hi, everyone.
I have a trouble when trying to generate static pre-render with Angular Universal
Can anybody help me?