javascript - RxJs: How to "listen" to change on a subscription when it receives a stream? -


i'm new angular 2 , observables, haven't found way "listen" change on subscription when receives stream, don't know if possible or if it's right way.

this used promises:

// constructor , more code // ...  ngoninit(): void {   this.loading.present();    this.getitems()       .then(() => this.loading.dismiss()); }  getitems(): promise {   return this.itemservice     .getitems()     .then(items => this.items = items); }  refresh(refresher): void {   this.getitems()       .then(() => refresher.complete()); } 

i've tried subscription/observables don't know how:

// constructor , more code // ...  ngoninit(): void {   this.loading.present();    this.getitems()       .subscribe(() => this.loading.dismiss()); }  getitems(): subscription {   return this.itemservice     .getitems()     .subscribe(items => this.items = items); }  refresh(refresher): void {   this.getitems()       .subscribe(() => refresher.complete()); } 

and of course, compilation error: property 'subscribe' not exist on type 'subscription', on how achieve observables (rxjs)?

a subscription listener, can't listen listener, can you?

instead, need return observable able subscribe to. change function follow (not tested):

getitems(): observable<any> {   let obs = this.itemservice.getitems().share();   obs.subscribe(items => this.items = items);   return obs; } 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -