Generate Service using Angular CLI

Open the Terminal in Visual Studio Code, select OctopusCodes.com folder and go to your project directory.

Click Image to Zoom

Type the command “ng generate service product” on the command prompt to generate ProductService.

Click Image to Zoom

Angular CLI will generate 2 files in the app folder:

  • product.service.spec.ts
  • product.service.ts
Click Image to Zoom

To generate service in a specific folder, type the command “ng generate service services/product” on the command prompt to generate ProductService in services folder.

Click Image to Zoom

Angular CLI will generate 2 files in the services folder:

  • product.service.spec.ts
  • product.service.ts
Click Image to Zoom