The error There are multiple modules with names that only differ in casing.
is indicating the wrong import is being targeted with how you are trying to use Observable
.
The import should be with a capital "O" like:
import { Observable } from 'rxjs/Observable';
This will import the individual Observable
operator, which be used in combination with operators such as catch
or throw
on created Observables.
import 'rxjs/add/operator/catch';
import 'rxjs/add/observable/throw';
To import the full Observable object you'd import it like this:
import { Observable } from 'rxjs/Rx'
Update:
With newer versions of RxJS (5.5+) operators such as map()
and filter()
can used as pipeable operators in combination with pipe()
rather than chaining. They are imported such as:
import { filter, map, catchError } from 'rxjs/operators';
Keep in mind terms such as throw
are reserved/key words in JavaScript so the RxJS throw
operator is imported as:
import { _throw } from 'rxjs/observable/throw';
Update:
For newer versions of RxJS (6+), use this:
import { throwError } from 'rxjs';
and throw an error like this:
if (error.status === 404)
return throwError( new NotFoundError(error) )
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…