angular - ERROR 错误:StaticInjectorError(AppModule)[UserformService -> HttpClient]:
问题描述
在尝试添加 PrimeNG 表时,我在这里破坏了我的构建:https ://github.com/BillyCharter87/Tech-O-Dex-UI/tree/BrokeIt
我记得将我package.json
的从 TypeScript 2.3.4 更新到 2.4.0 并且由于(我认为)我正在使用Headers
和Http
我的 POST 调用这一事实而中断。我尝试将其设置回 2.3.4 无济于事。我已经通过添加以下内容修复了我可以解决的问题:
import { HttpClient, HttpHeaders } from "@angular/common/http";
但仍然遇到我现在为HttpClient
. 我曾尝试HttpClient
像这样导入提供程序:providers: [HttpClient]
对于我的 app.module.ts。
完整的错误如下:
AppComponent.html:9 ERROR Error: StaticInjectorError(AppModule)[HttpClient -> HttpHandler]:
StaticInjectorError(Platform: core)[HttpClient -> HttpHandler]:
NullInjectorError: No provider for HttpHandler!
解决方案
确保您已导入HttpClientModule
而不是直接添加HttpClient
到提供程序列表中。
有关更多信息,请参阅https://angular.io/guide/http#setup。
HttpClientModule
实际HttpClient
为您提供。请参阅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 { }
推荐阅读
- keras - Keras 词嵌入矩阵的第一行为零
- javascript - 为什么 For..in(loop) 总是破坏它所在的函数?
- python - 在使用 keras 进行训练的每个 epoch 之后获取所有验证细节
- performance - 如何在 Linux 开发笔记本电脑上修复“java.lang.OutOfMemoryError:无法创建新的本机线程”
- laravel - 如何显示所有信息的动物?
- python-3.x - python多处理fastq函数
- javascript - PWA:资产体积小,但 chrome 缓存存储大约 500Mb
- wordpress - 我有 WP 多站点、ACM 颁发的 SSL、负载均衡器设置,如何为用户提供 HTTPS 访问?
- ios - 另一个订阅触发后立即取消订阅的最佳实践
- entity-framework-core - 使用 Entity Framework 核心在数据库中保存数据时更新 MemoryCache web.api