Singleton service in Angular

There are two ways to make a service a singleton in Angular:

  • Set the providedIn property of the @Injectable() to "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 {

Leave a Reply

Your email address will not be published. Required fields are marked *