Services
Let's explore services in Angular and create our own.
We'll cover the following
Now that we’ve seen how our AppComponent fits into AppModule, it’s time to revisit the other features of Angular (services, directives, and pipes). These can be aggregated into modules, along with components.
In Angular, we use services to manage the data that’s used within an application. We could use a service to manage the data for users, for example. This service could let us create new users, retrieve additional details about a user, update details about the user, or delete the user. These services can be used throughout our application within any component or module that needs to leverage its functionality.
Within this course, we’ll be using services primarily to make HTTP requests to an API to either save, update, or retrieve data from a database. For now, we’ll start with a simple service that returns some hard-coded data.
ng-features
First, we’ll use the CLI to generate a service for us. Click on the terminal below to connect it. Once it’s connected, run this command to generate the service.
ng g service ng-features
Get hands-on with 1400+ tech skills courses.