window is not defined angular universal third library

后端 未结 5 705
臣服心动
臣服心动 2021-01-03 03:59

I am working with the library ng2-mqtt and I used it im my component like this:

 import \'ng2-mqtt/mqttws31.js\';
declare var Paho: any;

No

5条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-03 04:07

    Angular 6 In server.ts use:

    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;
    

提交回复
热议问题