代码之家  ›  专栏  ›  技术社区  ›  NeitoFR

在离子4应用程序中使用@ionic native/http

  •  0
  • NeitoFR  · 技术社区  · 7 年前

    我正在尝试使用 @ionic-native/http 我的爱奥尼亚4应用程序内的模块。它是新的,并尝试在home.page组件中使用它。但我得到这个错误: error Uncaught Error: Unexpected value 'HTTP' imported by the module 'AppModule'. Please add a @NgModule annotation.

    我尝试了很多东西,甚至用 @beta 模块, 我在 app.module.ts 在imports[]数组中。

    她是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) {}
    ....
      }

    我错过了什么?

    祝大家晚上愉快。

    1 回复  |  直到 7 年前
        1
  •  2
  •   Gary Großgarten    7 年前

    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

    推荐文章