Angular2: convert array to Observable
import { of } from 'rxjs';
return of(this.contacts);
You're right there. If you already have the data in memory, you can use of
observable (equivalent of return/just
in RxJS 4).
getContacts() {
if(this.contacts != null)
{
return Observable.of(this.contacts);
}
else
{
return this.http.get(url)
.map(res => <Contact[]> res.json())
.do(contacts => this.contacts = contacts)
.catch(this.handleError);
}
}