Creating an Observable for Mock Data in Angular 2

Chris picture Chris · Feb 15, 2016 · Viewed 25.8k times · Source

I am trying to return an Observable from a service with mock data.

I am returning this from my service :

return Observable.of(new Object()).map(MOCKACCOUNT =>JSON.stringify(MOCKACCOUNT));

I get an error

Observable_1.Observable.of is not a function.

Am I missing some include? I am importing

import {Observable} from "rxjs/Observable";

Note: I was returning a mock promise prior but based on my understanding I would not be able to interpolate the value. For example {{returnFromServiceStoredInExportedClass.name}}

Answer

Günter Zöchbauer picture Günter Zöchbauer · Feb 15, 2016

Looks like

import {Observable} from "rxjs/Observable";

should be

import {Observable} from "rxjs/Rx";

See also Angular2 RxJS getting 'Observable_1.Observable.fromEvent is not a function' error