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 inject() vs DI

Discussão em 'Angular' iniciado por xnm, Maio 29, 2025.

  1. xnm

    xnm Guest

    When injecting a service in Angular what could be more optimized ? Constructor-Based Dependency Injection or Inject ? I have the perception that inject is more optimized, because when we choose this path over the constructor one, due to the behavior of native class fields in JavaScript they are initialized before the constructor runs, an example:

    private service = inject(Service); private get = this.service.get;

    Is this correct ? Or is my perception of the behavior under the hood wrong ?

    Multiple researches and discussions with senior devs, didn't get to a solid conclusion.

    Thank you in advance!

    Continue reading...

Compartilhe esta Página