Service



Service 
For data or logic that isn't associated with a specific view, and that you want to share across components, you create a service class. A service class definition is immediately preceded by the @Injectable() decorator. The decorator provides the metadata that allows other providers to be injected as dependencies into your class.

Angular supports two-way data binding, meaning that changes in the DOM, such as user choices, are also reflected in your program data.

A singleton service is a service for which only one instance exists in an app.
There are two ways to make a service a singleton in Angular:
Declare root for the value of the @Injectable() providedIn property. This tells Angular to provide the service in the application root.

Include the service in the AppModule or in a module that is only imported by the AppModule
import { Injectable } from '@angular/core';
  providedIn: 'root',
})
export class UserService {}


Ref: angular.io