Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Observable fromArray

Tags:

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

like image 303
intuix Avatar asked Mar 09 '16 11:03

intuix


1 Answers

should that be...

Rx.Observable.from(yourarray)

fromArray seems to be deprecated

like image 126
ade jones Avatar answered Oct 14 '22 05:10

ade jones