Reputation: 845
my web application breaks (won't load) when I use 'new Observable()' anywhere in a method or otherwise.
Angular version 2.1.0
RxJs 5.0.0-beta.12
These are my imports in the .ts-file:
import { Injectable } from '@angular/core';
import { DSUnit } from '../model/dsunit';
import { Headers, Http, Response } from '@angular/http';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/map';
import 'rxjs/add/observable/throw';
import 'rxjs/Rx';
import { DSCategory } from './../model/dscategory';
import { Observable } from 'rxjs';
When I have this piece of code it breaks:
private handleError(error: any) : Observable<any> {
let errMsg = "argh";
return new Observable(); // <-- "offending" code
}
with this error on the console of Chrome:
(SystemJS) XHR error (404 Not Found) loading http://localhost:3000/node_modules/rxjs(…)
And when I remove the offending line, and have this instead:
private handleError(error: any) : Observable<any> {
let errMsg = "argh";
return null; // <-- "works"
}
my web application loads with no errors.. of course it breaks when the 'catch'-statement tries to handle an error, but that will work once I get past the hurdle with
"new Observable()"
Any ideas, anyone?
Upvotes: 0
Views: 695
Reputation: 845
Damn it... the 'auto import' in Visual Studio Code had messed up my import.
When I import '{Observable}' it should not be
import {Observable} from 'rxjs'
it should be
import {Observable} from 'rxjs/Rx'
Upvotes: 0
Reputation: 10824
You could try this:
Observable.of(errMsg);
or
Observable.throw(errMsg);
depending on the caller.
Upvotes: 2