twilliams
twilliams

Reputation: 475

Newing an Observable in Angular2 prevents bootstrap with no error

Using Angular2 Beta 13, when I create a new observable my entire app fails to load, and I receive no errors in the console. Angular simply doesn't get bootstrapped. Adding a break-point to try and see how the program flows leads nowhere.

What on earth causes this, and how do I work around it?

import { Observable, Observer } from "rxjs";

And this is part of the class

metrics: Observable<IMembershipMetrics>;
private metricsObserver: Observer<IMembershipMetrics>;

constructor(private http: Http) {
        this.metrics = new Observable(observer => this.metricsObserver = observer).share();
    }

As soon as I remove that line newing the observable, the whole program runs again.

Upvotes: 0

Views: 67

Answers (1)

drew moore
drew moore

Reputation: 32680

Unless you're doing something funky in your config, your import is wrong.

import { Observable, Observer } from "rxjs";

should be either

import { Observable, Observer } from "rxjs/Rx"; 

if you want to import the entire "kitchen sink" (almost never a good idea in production, but is convenient for dev), or:

 import { Observable } from "rxjs/Observable";
 import { Observer } from "rxjs/Observer";

if you want to import only Observable and Observer

For future reference, incorrect import statements will only break your app when you try to use them (which is why commenting out the line where you do so seems to eliminate the error). That said, there should always be a warning about them in your tsc output so keep an eye on that.

Upvotes: 2

Related Questions