Creating services for data in Angular
Sharing data across different layers of the application can be a common way to manage application state. In Angular, we can share data state through a provider known as a service. Services are often used as singleton classes in Angular, but they can also be scoped to specific modules or components of your application, if necessary. You should be using a service whenever you have a shared state of data in your application that is used by more than one part of your application.
The most common way to use a service is to set up a shared data source at the AppModule
level of your application. This will ensure that the service is available downstream to all other components and modules in your application.
Getting ready
Let's create a current user service to manage the current user in our application. To start with, we can use this service to do basic things for us, such as giving us the full name of the user when they create new blog posts. Going forward, we...