gpt4 book ai didi

angular - Ionic2 - 未捕获运行时错误( promise 中): Error: No provider for Http

转载 作者:搜寻专家 更新时间:2023-10-30 21:29:23 24 4
gpt4 key购买 nike

错误:

Runtime Error Uncaught (in promise): Error: No provider for 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 {
...
}

最佳答案

提供商默认包含 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()
],
...

关于angular - Ionic2 - 未捕获运行时错误( promise 中): Error: No provider for Http,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44890819/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com