如何在 angular2-meteor 项目中使用 RxJS?

How to use RxJS in an angular2-meteor project?

我有一个 angular2-meteor 项目。

我尝试使用 RxJS,所以我在我的代码中添加了这些:

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

但是当我运行它时,它显示:

Cannot find module 'rxjs/Observable'.

我需要安装来自 Atmosphere 的软件包吗?

你应该导入:

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

而不是这个:

import {Observable} from 'rxjs/Observable';

我没有 Atmosphere 但这个包是你在 package.json 文件中定义的:

{
  "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"
  },
  (...)
}

你需要它来使 Angular2 工作。例如 class EventEmitter class 扩展了作为 rxjs 库的一部分的 Subject class...