Return to site

ANGULAR INTERVIEW QUESTION: What is a service?

An Angular service is a class that is generally instantiated one time during all the Angular application lifecycle, thanks to the root injector.

 

import { Injectable } from '@angular/code';

@Injectable({
   providedIn: 'root'
})

export class SomeService {}

 

The goal of a service is to organize and to share the business logic between the different Angular application components.

So, an Angular service is a class that can be used in your application thanks to dependency injection that enables code sharing.