Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

AddhttpClient option to httpResource #62616

Open
Labels
area: common/httpIssues related to HTTP and HTTP Clientcross-cutting: resourceIssues related to the newly introduced resource / httpResource
Milestone
@MillerSvt

Description

@MillerSvt

Which @angular/* package(s) are relevant/related to the feature request?

common

Description

In our project we use modular HttpClient with different setup of interceptors for accessing different API's.

We createcreateHttpClient helper for that:

exportfunctioncreateHttpClient(...features:HttpFeature<HttpFeatureKind>[]):HttpClient{assertInInjectionContext(createHttpClient);constinjector=createEnvironmentInjector([provideHttpClient(...features)],inject(EnvironmentInjector),);returninjector.get(HttpClient);}

And we use this helper inside{provide: CUSTOM_HTTP_CLIENT_TOKEN, useFactory: () => createHttpClient()}.

It works until we migrate tohttpResource, because there is no way to specify what instance ofHttpClient should be used.

Proposed solution

Add optionhttpClient?: HttpClient toHttpResourceOptions.

Alternatives considered

Create custom injection context, and runhttpResource inside it:

functionbindHttpResource<T>(resourceFactory:()=>HttpResourceRef<T>,httpClientToken:InjectionToken<HttpClient>):HttpResourceRef<T>{assertInInjectionContext(bindHttpResource);constinjector=Injector.create({providers:[{provide:HttpClient,useExisting:httpClientToken,}],parent:inject(Injector),});returnrunInInjectionContext(injector,resourceFactory);}

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: common/httpIssues related to HTTP and HTTP Clientcross-cutting: resourceIssues related to the newly introduced resource / httpResource

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp