How to generate service in angular using CLI

Using Angular CLI we can quickly generate service components. Before that make sure you have

  1. npm
  2. angular CLI

preinstalled on your system. For better understanding of angular project structure I suggest the following post

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

Published by


A developer,teacher and a blogger obsessed with Python,Dart and open source world from India

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.