Angular services were introduced to write code shareable among components. So if we need a piece of code for many components, it's recommended to create a single reusable service, and wherever we need that piece of code, we can just inject that service to the component and use its methods as needed.
Services are used to abstract application logic. They are used to provide a single responsibility for a particular action. Single responsibility allows components to be easily tested and changed. This is because the focus is on one component and not all the inner dependencies.
Mostly, a service acts as the data source of any application. Whenever we need a piece of code to communicate with the server to get data (mostly JSON), we use a service.
This is because most components need to access data, and everyone can inject the common service as required. So, we have a commonly used piece of code, which is actually the data layer for our application. We should move those parts to...