3

I have an angular2-meteor project.

I tried to use RxJS, so I added these in my code:

import {Observable} from 'rxjs/Observable';
import 'rxjs/Rx';

But when I run it, it shows:

Cannot find module 'rxjs/Observable'.

Do I need install any package from Atmosphere?

Hongbo Miao
  • 45,290
  • 60
  • 174
  • 267

1 Answers1

1

You should this import:

import {Observable} from 'rxjs/Rx';
import 'rxjs/add/operator/map'; // for example to add a specific operator

instead of this one:

import {Observable} from 'rxjs/Observable';

I don't Atmosphere but this package is what you define in the package.json file:

{
  "name": "apispark-angular2",
  (...)
  "dependencies": {
    "angular2": "2.0.0-beta.0",
    "es6-promise": "^3.0.2",
    "es6-shim": "^0.33.3",
    "reflect-metadata": "0.1.2",
    "rxjs": "5.0.0-beta.0",  <---------------
    "systemjs": "0.19.6",
    "zone.js": "0.5.10"
  },
  (...)
}

You need it to make work Angular2. For example class EventEmitter class extends the Subject class that is part of the rxjs library...

Thierry Templier
  • 198,364
  • 44
  • 396
  • 360
  • Thanks, but angular2-meteor is little different. I updated in my question. I still haven't found way to make Rx run. – Hongbo Miao Feb 05 '16 at 15:07
  • What did you include into your HTML page regarding RxJS? `node_modules/rxjs/bundles/Rx.js`? Because in this file, you can see at the end that the `rxjs/Rx` module is registered: `System.register("rxjs/Rx", ["rxjs/Subject", "rxjs/Observable", ...`. The version I use is the `5.0.0-beta.0` one. Do you have the same? – Thierry Templier Feb 05 '16 at 15:19
  • I am not 100% sure. In the angular2-meteor project we don't add in HTML directly. However, inside the file **"typings/main.d.ts"** I added in tsconfig.json, it is `/// `, and the **rx.d.ts** content is same like [this](https://raw.githubusercontent.com/DefinitelyTyped/DefinitelyTyped/4d86cc24082d6703ecaee46ecc970bd0ac744236/rx/rx.d.ts) – Hongbo Miao Feb 05 '16 at 15:39
  • You can see [here](http://www.angular-meteor.com/tutorials/socially/angular2/bootstrapping), after step 0.6 – Hongbo Miao Feb 05 '16 at 15:41
  • Okay I see. What do you have in the `index.html` page you get in the browser regarding ` – Thierry Templier Feb 05 '16 at 16:51
  • I don't have `index.html` and `package.json`, I only have `tsconfig.json`. But I tried to add `index.html`, but still no idea what should be inside of ` – Hongbo Miao Feb 05 '16 at 17:19
  • wow, it is weird, I tried again today using `import {Observable} from 'rxjs/Rx';` `import 'rxjs/add/operator/map';`, it is working!! thanks!! – Hongbo Miao Mar 20 '16 at 02:52