错误错误:StaticInjectorError(AppModule)[UserformService-> HttpClient]: [英] ERROR Error: StaticInjectorError(AppModule)[UserformService -> HttpClient]:

查看:250
本文介绍了错误错误:StaticInjectorError(AppModule)[UserformService-> HttpClient]:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试添加PrimeNG表时,我在这里破坏了构建: https ://github.com/BillyCharter87/Tech-O-Dex-UI/tree/BrokeIt

While trying to add a PrimeNG table I broke my build here: https://github.com/BillyCharter87/Tech-O-Dex-UI/tree/BrokeIt

我记得更新了软件包.json 从TypeScript 2.3.4到2.4.0,并且由于(我认为)我正在使用 Headers Http 进行我的POST调用。我尝试将其设置回2.3.4无济于事。我通过添加以下内容解决了可能的问题:

I recall updating my package.json from TypeScript 2.3.4 to 2.4.0 and it broke due to (I think) the fact that I was using Headers and Http for my POST call. I tried setting it back to 2.3.4 to no avail. I have fixed what I could by adding in:

import { HttpClient, HttpHeaders } from "@angular/common/http";

但仍然遇到错误,我现在为 HttpClient 。我尝试将 HttpClient 导入到提供程序中,如下所示:提供者:[HttpClient] 用于我的app.module.ts。

but still running into the Error I have now for the HttpClient. I have tried importing HttpClient into the providers like so: providers: [HttpClient] for my app.module.ts.

完整错误如下:

AppComponent.html:9 ERROR Error: StaticInjectorError(AppModule)[HttpClient -> HttpHandler]: 
StaticInjectorError(Platform: core)[HttpClient -> HttpHandler]: 
NullInjectorError: No provider for HttpHandler!


推荐答案

确保已导入 HttpClientModule ,而不是直接在提供程序列表中直接添加 HttpClient

Make sure you have imported HttpClientModule instead of adding HttpClient direcly to the list of providers.

请参见 https://angular.io/guide/http#setup 了解更多信息。

HttpClientModule 实际上为您提供了 HttpClient 。参见 https://angular.io/api/common/http/HttpClientModule

The HttpClientModule actually provides HttpClient for you. See https://angular.io/api/common/http/HttpClientModule:

代码示例:

import { HttpClientModule, /* other http imports */ } from "@angular/common/http";

@NgModule({
    // ...other declarations, providers, entryComponents, etc.
    imports: [
        HttpClientModule,
        // ...some other imports
    ],
})
export class AppModule { }

这篇关于错误错误:StaticInjectorError(AppModule)[UserformService-> HttpClient]:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆