angular use service in component code example

Example 1: angular create a service

>>> ng generate service service_name
or
>>> ng generate service /folder-name/service-name

Example 2: how to inject service in component angular 6

you can inject service in components constructor:
constructor(public anyService: Service){}

Example 3: angular how to use service in class

import { <service name>Service } from '../<service path>';
you can inject service in components constructor:
constructor(public anyService: Service){}