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

Functional style interceptors - How to provide them with dependencies

Discussão em 'Angular' iniciado por turtle, Maio 14, 2025.

  1. turtle

    turtle Guest

    Imagine situation where you provide any lib to client. Simple scenario, spinner interceptor which needs spinner service.

    In old way it was possible to:

    providers: [
    {
    provide: HTTP_INTERCEPTORS,
    useClass: AuthInterceptor,
    multi: true
    },
    SpinnerService
    ]


    Then the client library could provide it forRoot or even in new way

    export const provideAuthInterceptor = () =>
    makeEnvironmentProviders([
    {
    provide: HTTP_INTERCEPTORS,
    useClass: AuthInterceptor,
    multi: true
    },
    SpinnerService

    ]);


    how can this be done in new way with functional style? I mean it must be provided with provideHttpClient like:

    export const provideAppHttpInterceptors = () =>
    makeEnvironmentProviders([
    SpinnerService,
    provideHttpClient(withInterceptors([
    authInterceptor,
    loggingInterceptor
    ]))
    ]);


    But client already use provideHttpClient, so it will override it right? So client must provide service and intercepor or his own, we cannot provide him a simple function to use.

    At first all the new stuff from angular looked cool but the more I use it the worse it seems than the old solutions.

    Continue reading...

Compartilhe esta Página