gpt4 book ai didi

angular - 错误 NullInjectorError : No provider for HttpClient:

转载 作者:行者123 更新时间:2023-12-03 08:00:18 27 4
gpt4 key购买 nike

ERROR NullInjectorError: R3InjectorError(PaceGeneratorLibraryComponentLoader)[HttpClient -> HttpClient -> HttpClient -> HttpClient]: 
NullInjectorError: No provider for HttpClient!
at NullInjector.get (core.mjs:6367:27)
at R3Injector.get (core.mjs:6794:33)
at R3Injector.get (core.mjs:6794:33)
at R3Injector.get (core.mjs:6794:33)
at R3Injector.get (core.mjs:6794:33)
at ChainedInjector.get (core.mjs:13824:36)
at lookupTokenUsingModuleInjector (core.mjs:3293:39)
at getOrCreateInjectable (core.mjs:3338:12)
at ɵɵdirectiveInject (core.mjs:10879:12)
at NodeInjectorFactory.DetailsComponent_Factory [as factory] (ɵfac.js? [sm]:1:1)

我在使用HttpClient获取后端数据时遇到了上述错误。我已将 HttpModule 包含在我的 NgModule 中,但它似乎不起作用。

@NgModule({
declarations: [
AppComponent,
WidgetContainerComponent
],
exports: [],
imports: [
AppRoutingModule,
BrowserAnimationsModule,
HttpClientModule,
BrowserModule,
ToastrModule.forRoot(),
ModalModule.forRoot(),
PlatformCoreBaseModule,
MsalModule.forRoot(getMsalConfig(environment).msalInstanceConfig, getMsalConfig(environment).msalGuardConfig, undefined),

],
providers: [
AppStateService,
ClientSettingsService,
DisplayStateService,
Title,
HttpClientModule,
WebPlatformApiService,
DynamicComponentLoader,

我已经尝试了几个小时,但没有任何想法。

最佳答案

在导入数组中使用 HttpClientModule,而不是在提供程序数组中:

import { HttpClientModule } from '@angular/common/http';

@NgModule({
imports: [
//Module...

HttpClientModule,

],
declarations: [
//component
//pipe
//directive
],
providers :[
//services...
],
exports :[
// some components or pipe or directive in the declarations tab
]
bootstrap: [AppComponent]
})

关于angular - 错误 NullInjectorError : No provider for HttpClient:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74543173/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com