Best way to replace deprecated Events

Thank you very much both of you, as always, you helped me a lot.

This is very sad to know, I believe the core of my project is like this. Adding a little more information about my problem, my main page in this case is basically an UI with buttons and menus. My component is an OpenLayers map and is at the center of all this UI, most of the app’s functions are fully linked with that component’s functions and are currently accessed through Events. I defined the OpenLayers map as a component because it was a suggestion someone in Stack Exchange GIS gave me very early in my app development.

But at least I manage to put all of you say together and made it work without using events. From this suggestion from @rapropos and this example I created a service only to listen the functions from the page and link it to the component. What I did:

In MyService:

private myObservable = new Subject<string>();
currentData = this.myObservable.asObservable();
serviceFunction() {
	this.myObservable.next("randomFunction");
}

In MyPage:

randomFunction() {
	this.randomService.serviceFunction();
}

In MyComponent:

this.randomService.currentData.subscribe(value => {
	console.log("randomFunction was fired!");
});

Which is now working as expected! Please, if there is still a problem with this method tell me so I can fix it, otherwise I will use this service in the future to replace the Events.

1 Like