【发布时间】:2018-08-29 10:43:44
【问题描述】:
我在尝试启动我的应用时遇到了该错误。
ERROR
Error: StaticInjectorError(AppModule)[ApiUserService -> HttpClient]:
StaticInjectorError(Platform: core)[ApiUserService -> HttpClient]:
NullInjectorError: No provider for HttpClient!
Stack trace:
_NullInjector.prototype.get@webpack-internal:///./node_modules/@angular/core/esm5/core.js:1218:19
resolveToken@webpack-internal:///./node_modules/@angular/core/esm5/core.js:1516:17
tryResolveToken@webpack-internal:///./node_modules/@angular/core/esm5/core.js:1458:16
StaticInjector.prototype.get@webpack-internal:///./node_modules/@angular/core/esm5/core.js:1326:20
resolveToken@webpack-internal:///./node_modules/@angular/core/esm5/core.js:1516:17
tryResolveToken@webpack-internal:///./node_modules/@angular/core/esm5/core.js:1458:16
StaticInjector.prototype.get@webpack-internal:///./node_modules/@angular/core/esm5/core.js:1326:20
resolveNgModuleDep@webpack-internal:///./node_modules/@angular/core/esm5/core.js:11070:12
NgModuleRef_.prototype.get@webpack-internal:///./node_modules/@angular/core/esm5/core.js:12303:16
resolveDep@webpack-internal:///./node_modules/@angular/core/esm5/core.js:12793:12
createClass@webpack-internal:///./node_modules/@angular/core/esm5/core.js:12655:29
_createProviderInstance@webpack-internal:///./node_modules/@angular/core/esm5/core.js:12632:20
createProviderInstance@webpack-internal:///./node_modules/@angular/core/esm5/core.js:12473:12
createViewNodes@webpack-internal:///./node_modules/@angular/core/esm5/core.js:13945:53
createRootView@webpack-internal:///./node_modules/@angular/core/esm5/core.js:13847:5
我不知道如何解决,错误似乎在我的 ApiUserService 中,
https://gist.github.com/LarsE343/4fe09a513e4d0d77564a4b0eac30b8e2 //链接到 ApiUserService Gist [完整文件]
【问题讨论】:
-
嗨!欢迎来到堆栈溢出。请参阅How to Ask 以及如何创建minimal reproducible example:请在问题本身中发布相关代码(包括您的主模块,可能称为
app.module.ts)的所有 和详细信息。为了便于阅读,我已经为您对错误进行了代码格式化,并删除了错误的最后一部分,因为相关部分,就像大多数堆栈跟踪一样,就在顶部。谢谢! -
另外,关于“当我启动我的应用程序”,有很多方法可以启动 Angular 应用程序。你到底发布了什么:
ng serve或其他什么? -
当您收到错误消息时,您应该搜索/谷歌该错误消息。这就是他们的目的,引导你找到正在发生的任何问题的根源。在这种情况下,错误是
NullInjectorError: No provider for HttpClient。如果您在 google 上搜索过,您会看到上述建议的副本,那是第一个返回的结果。 -
如果您仍然卡住,您将不得不通过创建minimal reproducible example 来发布您的代码。另见How to Ask。
-
我的建议是关于如何提出一个好问题的更笼统的建议,但@Igor 的建议至关重要,甚至在问这里之前。
标签: node.js angular typescript webpack angular5