Category service

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 CategoryListComponent and 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.

Rename the category.ts to category.service.ts to follow ...

Get Web Development with Bootstrap 4 and Angular 2 - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.