[英]ionic-native/http emit error “NullInjectorError: No provider for HTTP!”
[英]Use @ionic-native/http in Ionic 4 Application
我正在尝试在Ionic 4应用程序中使用@ionic-native/http
模块。 它是新的,正在尝试在home.page组件中使用它。 但是我得到这个错误: Uncaught Error: Unexpected value 'HTTP' imported by the module 'AppModule'. Please add a @NgModule annotation.
我尝试了很多事情,即使使用@beta
模块,我也在app.module.ts
和imports []数组中添加了import语句。
她是app.module.ts
... import { HTTP } from '@ionic-native/http/ngx'; ... @NgModule({ declarations: [AppComponent], entryComponents: [], imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule, HTTP], ...
这是home.page.ts文件
... import { HTTP } from '@ionic-native/http/ngx'; @Component({ selector: 'app-home', templateUrl: 'home.page.html', styleUrls: ['home.page.scss'], }) export class HomePage { constructor(private http: HTTP) {} .... }
我想念什么?
大家晚上好。
HTTP不是一个模块。 您必须将其放在应用程序模块提供程序数组下。
...
import { HTTP } from '@ionic-native/http/ngx';
...
@NgModule({
declarations: [AppComponent],
entryComponents: [],
imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule],
providers: [HTTP]
...
供参考: https : //ionicframework.com/docs/native/#Add_Plugins_to_Your_App_Module
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.