I mentioned in Chapter 5, Routing, about the necessity to decouple the data from the presentation logic when implementing SPA. I partially realized it in the category and product views. The
WelcomeComponent use category returns from the
getCategories function. Right now it is not suffering, but when we start getting and updating data from the server, we will need more functions. Better hide the implementation detail inside the single reusable data service class to use it in multiple components.
Let's refactor the category data acquisition business to a single service that provides categories, and share that service with all components that need them.
category.service.ts to follow ...