最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Is there a way to import rxjs into a plain js web custom component? - Stack Overflow

programmeradmin4浏览0评论

I'm trying to create web custom ponents using plain js. I would like to use rxjs and observables to fetch json content from a REST endpoint that I am also creating using python pyramid. However, an error - 'TypeError: global is undefined' - is being thrown when I import rxjs.

import '/@reactivex/[email protected]/dist/global/rxjs.umd.js';

also tried:

import '.5.2/rxjs.umd.js';

I would like to NOT use npm at all.

I'm trying to create web custom ponents using plain js. I would like to use rxjs and observables to fetch json content from a REST endpoint that I am also creating using python pyramid. However, an error - 'TypeError: global is undefined' - is being thrown when I import rxjs.

import 'https://unpkg./@reactivex/[email protected]/dist/global/rxjs.umd.js';

also tried:

import 'https://cdnjs.cloudflare./ajax/libs/rxjs/6.5.2/rxjs.umd.js';

I would like to NOT use npm at all.

Share Improve this question edited Aug 18, 2019 at 13:47 ferd tomale asked Aug 18, 2019 at 13:22 ferd tomaleferd tomale 90310 silver badges24 bronze badges 1
  • found out how. I was supposed to put the url into a script tag and then use it in the js file as: js const { Observable, from } = rxjs; – ferd tomale Commented Aug 18, 2019 at 14:12
Add a ment  | 

2 Answers 2

Reset to default 14
<script src="https://cdnjs.cloudflare./ajax/libs/rxjs/6.5.2/rxjs.umd.js"></script>

then:

const { Observable, from } = rxjs;

With NodeJS and plain JS:

<script src="node_modules/rxjs/dist/bundles/rxjs.umd.js"></script>


   // And JS code sample...  
 
    thisworkStatus$ = rxjs.merge(
        rxjs.of(null),
        rxjs.fromEvent(window, 'online'),
        rxjs.fromEvent(window, 'offline')
    )

    this.applicationStatus$ = new rxjs.BehaviorSubject(this.getApplicationStatus());
发布评论

评论列表(0)

  1. 暂无评论