File for commonly used functions

In my app, there’re some functions I created that I use frequently across the app (getUser(), showAlert(), goto()…), and I put them in a .ts service file which I inject in the pages.

Is there a better way of doing this?

Generally i would say, it’s correct. I’m doing this the same, but you should not use only one service for all this stuff. A function like getUser() should be Part of a user.service.ts, which maybe in the future will do more user related stuff.

For Alerts, Popups etc i have a created a popup.service.ts (but i did this because i developed my own alerts, toasts, popover. etc) which needs to be managed.

For navigation i’m only using the app.component.ts. I created a Transfer-Service which works like an event controller. I’m doing this, because the app.component.ts includes (normally) the nav element, so i only change the nav in here.

1 Like