Site icon Tutorial

Singleton Services

Go back to Tutorial

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

Beginning with Angular 7.0, the preferred way to create a singleton services is to specify on the service that it should be provided in the application root. This is done by setting providedIn to root on the service’s @Injectable decorator:

src/app/user.service.0.ts

import { Injectable } from ‘@angular/core’;

@Injectable({

providedIn: ‘root’,

})

export class UserService {

}

 

Go back to Tutorial

Exit mobile version