@karvanj wrote:
With Ionic events being deprecated I am having difficulties going to observables.
For a simple page refresh that is executed in a subcomponent of the page, I would:
In my main page it subscribes to the event to refresh:
constructor(){ this.eventFormRefresh = (obj) => { this.fetch(obj.isReset); }; this.events.subscribe('form:refresh', this.eventFormRefresh); } ngOnDestroy(): void { this.events.unsubscribe('form:refresh', this.eventFormRefresh); }
In a subcomponent I activate the refresh by publishing the ‘form:refresh’ event as so:
this.events.publish('form:refresh');
To do the above via RXJS I was shown a solution using subjects as below:
Common Service:
@Injectable() export class EventService{ private formRefreshAnnouncedSource = new Subject(); formRefreshSource$ = this.formRefreshAnnouncedSource.asObservable(); publishFormRefresh(){ this.formRefreshAnnouncedSource.next() } }
then publish like
this.eventService.publishFormRefresh();
The question I have is the above method the angular way to use observables?
I have seen tutorials that use new Observable instead but do not know how to implement in the similar fashion as ionic events.
Appreciate if I can get any guidance on this as I do find observables confusing to say the least. Thanks in advance!
Posts: 1
Participants: 1