Thursday, 27 December 2018

How to generate a service in Angular cli?

to generate a service:

ng generate service customer

OR 

ng g s customer





ng generate service customer command creates the customer.service.ts file but it is not registered with any module. If it is not registered with any module we can not use in our application. We can manually register with the module or else we can instruct the angular cli to register while creating the service as follows.

ng generate service employee -module=app.module 

or

ng g s employee -m=app.module 

When we are creating a service it will not be placed in a specific folder, whereas we can tell the angular cli to create its own folder for a service that the Angular CLI is generating, set --flat option to false as shown below. 

ng g s student1 --spec=false --flat=false








No comments:

Post a Comment