There are two ways to make a service a singleton in Angular:
providedIn
property of the @Injectable()
to "root"
.AppModule
or in a module that is only imported by the AppModule
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root',
})
export class UserService {
}