1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

Angular @Injectable() - there is no 'providers' key, so how to implement the Dependency...

Discussão em 'Angular' iniciado por Alex Lavrik, Junho 5, 2025.

  1. Alex Lavrik

    Alex Lavrik Guest

    Usually I used the providers array key in a@Component or @ngModule in order to provide a dependency object to implement the DI principle. For example:

    providers: [
    {provide: BaseDataService, useClass: UsersDataService} // where BaseDataService is an abstraction with methods to be implemented
    ]


    While Angular developers recommend using @Injectable ({provideIn: 'root' }) due to 'tree-shaking' possibility. But as I told earlier there's no providers array key among the parameters, useFactory only. So the question is - how do I? Or should I use the "classic" way with the providers array within a @Component()?

    Continue reading...

Compartilhe esta Página