【问题标题】:ERROR : StaticInjectorError(AppModule)[global]: StaticInjectorError(Platform: core)[global]: NullInjectorError: No provider for global错误:StaticInjectorError(AppModule)[global]: StaticInjectorError(Platform: core)[global]: NullInjectorError: No provider for global
【发布时间】:2019-08-29 06:06:14
【问题描述】:

我打开了我的 ionic 项目,但在浏览器中没有任何显示。我收到类似的错误 My Error

这是我在 app.module.ts 中的代码

import { HttpClientModule } from "@angular/common/http";
import { HttpModule } from '@angular/http';
imports: [
  HttpClientModule,
  HttpModule ,
 ],
providers: [
  Clipboard,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
 ],
bootstrap: [AppComponent]
  })

【问题讨论】:

  • 提供你的代码,否则没人能理解是什么问题
  • 是新建项目或已有项目问题,请详细说明。
  • 请更新您的代码
  • 我已经更新了我的问题
  • 当您尝试使用提供程序、导入或类似的东西并且没有在模块文件中正确声明它时,最有可能发生此错误。您可能忘记在提供程序或其他地方声明它。如果您可以粘贴整个代码,那么将更容易识别问题。如果你能做一个stackblitz会更好。

标签: angular ionic-framework


【解决方案1】:

有两个可能的原因 1. 如果您在服务中使用 HttpClient,则需要在模块文件中导入 HttpClientModule 并在导入数组中提及。

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

2) 如果您在服务中使用普通 Http,则需要在模块文件中导入 HttpModule 并在导入数组中提及它。

import { HttpModule } from '@angular/http'

【讨论】:

  • 感谢您的回答,我是 ionic 新手,您能给我举个例子吗?
  • 您只需从 app.module.ts 文件中删除 httpmodule 并在您的服务中使用 httpclient,如下所示:->import { HttpClientModule } from "@angular/common/http";进口:[HttpClientModule],提供者:[剪贴板,{提供:RouteReuseStrategy,useClass:IonicRouteStrategy}],引导程序:[AppComponent]})
  • 你能做一个stackblitz,这样我就可以通过代码了。
猜你喜欢
  • 1970-01-01
  • 2019-01-14
  • 1970-01-01
  • 2020-06-13
  • 1970-01-01
  • 1970-01-01
  • 2018-10-31
  • 1970-01-01
  • 2021-10-16
相关资源
最近更新 更多