typescript - create Observable<T> from result -


i'm trying angular2.

i noticed http service use obserable object instead of promise (i don't choice.. asyc/await arriving)

in service download list of plants webservice. clicking on plant show details using routing. in way when go back, plants downloaded again (becouse constructor called again).

to avoid want like:

public getplants():observable<plants[]> {        if (this._plants != null)         return observable.fromresult (this._plants); //this method not exists       return this._http.get('../../res/heroes.json')... } 

is there way that? how can import observable class in ts file?

thanks!

this working solution:

if (this._heroes != null && this._heroes !== undefined) {     return observable.create(observer => {         observer.next(this._heroes);         observer.complete();     }); } 

i hope best solution.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -