deen
deen

Reputation: 2305

ReferenceError: Rx is not defined

I am just started learning angular2 and I am trying to do sample of RxJs using angular2. It would be highly appreciated, If some one help me.

RxJs Code-

var obs = Rx.Observable.interval(500)
       .take(5)
       .do(i => console.log(i) );

package.json

  {
    "name": "angular-quickstart",
    "version": "1.0.0",
    "scripts": {
      "start": "tsc && concurrently \"tsc -w\" \"lite-server\" ",
      "lite": "lite-server",
      "postinstall": "typings install",
      "tsc": "tsc",
      "tsc:w": "tsc -w",
      "typings": "typings"
    },
    "license": "ISC",
    "dependencies": {
    "@angular/common": "~2.0.1",
    "@angular/compiler": "~2.0.1",
    "@angular/core": "~2.0.1",
    "@angular/forms": "~2.0.1",
    "@angular/http": "~2.0.1",
    "@angular/platform-browser": "~2.0.1",
    "@angular/platform-browser-dynamic": "~2.0.1",
    "@angular/router": "~3.0.1",
    "@angular/upgrade": "~2.0.1",
    "angular-in-memory-web-api": "~0.1.1",
    "bootstrap": "^3.3.7",
    "core-js": "^2.4.1",
    "reflect-metadata": "^0.1.8",
    "rxjs": "5.0.0-beta.12",
    "systemjs": "0.19.39",
    "zone.js": "^0.6.25"
    },
    "devDependencies": {
      "concurrently": "^3.0.0",
      "lite-server": "^2.2.2",
      "typescript": "^2.0.3",
      "typings":"^1.4.0"
    }
  }

Upvotes: 8

Views: 11392

Answers (3)

Ben Butterworth
Ben Butterworth

Reputation: 28472

Update 2020:

For those using the CDN listed on their readme, i.e. https://unpkg.com/rxjs/bundles/rxjs.umd.min.js.

The developers must have changed the global namespace for rxjs from Rx to rxjs, so use rxjs instead of Rx,

var obs = rxjs.Observable.interval(500)
       .take(5)
       .do(i => console.log(i) );

For more information, read the rxjs's README.md

Upvotes: 10

deen
deen

Reputation: 2305

I just removed the Rx before Observable-

var obs = Observable.interval(500)
   .take(5)
   .do(i => console.log(i) );

Upvotes: 3

englishPete
englishPete

Reputation: 847

  1. npm install rxjs

counter.ts

import {Observable} from 'rxjs/Observable';
import 'rxjs/add/observable/interval';

// To get the typescript compiler to recognise Rx.* execute.
// npm install @types/rx --save-dev

let obs = Observable.interval(1000);


obs.subscribe(value => console.log("Subscriber: " + value));
  1. tsc counter.ts
  2. node counter.js

    Subscriber: 0

    Subscriber: 1

    Subscriber: 2

^C

Upvotes: 0

Related Questions