Ionic2 - 未捕获的运行时错误(在承诺中):错误:没有Http的提供程序

时间:2017-07-03 17:03:47

标签: angular typescript ionic2 ionic3

错误:

  

运行时错误未捕获(在承诺中):错误:没有Http的提供程序

好吧,我确实有一个HTTP提供商,都注册了。 我有什么想法可以解决这个问题吗?

app.module.ts

import {NgModule, ErrorHandler} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {IonicApp, IonicModule, IonicErrorHandler} from 'ionic-angular';
import {MyApp} from './app.component';

import {StatusBar} from '@ionic-native/status-bar';
import {SplashScreen} from '@ionic-native/splash-screen';
import {GoldServiceProvider} from '../providers/gold-service/gold-service';

// ...

@NgModule({
    declarations: [
        MyApp,
        // ...
    ],
    imports: [
        BrowserModule,
        IonicModule.forRoot(MyApp)
    ],
    bootstrap: [IonicApp],
    entryComponents: [
        MyApp,
        // ...
    ],
    providers: [
        GoldServiceProvider,
        StatusBar,
        SplashScreen,
        {
            provide: ErrorHandler,
            useClass: IonicErrorHandler
        },
    ]
})
export class AppModule {
}

gold-service.ts:我的提供商服务

import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';

@Injectable()
export class GoldServiceProvider {
    ...    
}

1 个答案:

答案 0 :(得分:3)

默认情况下,提供商包含Http,为了在您的应用中使用Http,您需要将HttpModule添加到app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule, ErrorHandler } from '@angular/core';
import { HttpModule } from '@angular/http';
...
  imports: [
    BrowserModule,
    HttpModule,
    IonicModule.forRoot(MyApp),
    IonicStorageModule.forRoot()
  ],
...