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 theAppModule
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root',
})
export class UserService {
}