7

A Common practice is to include services in @NgModule.providers

@NgModule({
  providers: [
    MessageService
  ]
})

According to Angular tutorial, you can provide a service without specifying it in the @NgModule decorator, by using @injectable.providedIn

@Injectable({
  providedIn: 'root',
})
export class MessageService {...}

Is there any advantage for using the method presented in the Angular tutorial?

yuval.bl
  • 4,890
  • 3
  • 17
  • 31

0 Answers0