Using Angular CLI we can quickly generate service components. Before that make sure you have
- npm
- angular CLI
preinstalled on your system. For better understanding of angular project structure I suggest the following post
- Project Structure : Angularjs - Angular Project Structure
Install CLI
If you already have the angular CLI installed , skip this step
npm install @angular/cli
What is a service ?
A service in angular has special duties such as fetching and pushing data from the server and to the server. The service can be used by any components.
Generate service
Use the following command to generate service classes from the project root
ng g service service-name
Don’t forget to visit the source code page