Giter VIP home page Giter VIP logo

Comments (3)

kolkov avatar kolkov commented on June 2, 2024

Thanks! Is a bug for universal. I try to fix this.

from ngx-metrika.

yalesnikov avatar yalesnikov commented on June 2, 2024

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

from ngx-metrika.

vvasiloud avatar vvasiloud commented on June 2, 2024

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.

from ngx-metrika.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.