Observable fromArray

Viewed 41909

I currently have a problem with Angular2 and Observable object.

I have a Component who calls a Service : a real one linked to an api and a fake one.

The service linked to the API works well but when I use the fake one, I want to return an Array from Observable object but I have this error :"Observable_1.Observable.fromArray is not a function"

Here is my code :

Component :

this._raceService.list().subscribe(newRaces => { 

  this.races = newRaces;
}); 

Real Service :

list(){ return this._http.get('http://dev.backend.com/api.php', options).map(res => res.json()); }

Fake service :

list() { return Observable.fromArray([{ name: 'London' }]); }

Can you help me plz ?

Cheers

7 Answers

Answer needs to be updated for RxJS 6, it is now

import {from} from 'rxjs';

const observable = from([ { a: 1, b: 2 } ]);
Related