[英]Is there a way to import rxjs into a plain js web custom component?
I'm trying to create web custom components using plain js.我正在尝试使用纯 js 创建 Web 自定义组件。 I would like to use rxjs and observables to fetch json content from a REST endpoint that I am also creating using python pyramid.我想使用 rxjs 和 observables 从我也使用 python 金字塔创建的 REST 端点获取 json 内容。 However, an error - 'TypeError: global is undefined' - is being thrown when I import rxjs.但是,当我导入 rxjs 时,会抛出一个错误——“TypeError: global is undefined”。
import 'https://unpkg.com/@reactivex/rxjs@6.0.0/dist/global/rxjs.umd.js';
also tried:也试过:
import 'https://cdnjs.cloudflare.com/ajax/libs/rxjs/6.5.2/rxjs.umd.js';
I would like to NOT use npm at all.我根本不想使用 npm。
<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/6.5.2/rxjs.umd.js"></script>
然后:
const { Observable, from } = rxjs;
With NodeJS and plain JS:使用 NodeJS 和普通 JS:
<script src="node_modules/rxjs/dist/bundles/rxjs.umd.js"></script>
// And JS code sample...
this.networkStatus$ = rxjs.merge(
rxjs.of(null),
rxjs.fromEvent(window, 'online'),
rxjs.fromEvent(window, 'offline')
)
this.applicationStatus$ = new rxjs.BehaviorSubject(this.getApplicationStatus());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.