[英]No provider for Http! - migrating from angular 2 to 4
I have included HttpModule
in my import
as follows 我在
import
包含了HttpModule
,如下所示
app.module.ts app.module.ts
import { HttpModule, Http, XHRBackend, RequestOptions } from '@angular/Http';
import { ApiService } from '../services/api.service';
@NgModule({
imports: [
BrowserModule,
HttpModule,
.........
]
providers: [
ApiService,
.......
]
})
ApiService is my custom Service . ApiService是我的自定义服务。
app.component.ts app.component.ts
import { Component, OnInit,NgZone } from '@angular/core';
import { Platform, AlertController, Events } from 'ionic-angular';
import { HttpModule, Http, XHRBackend, RequestOptions } from '@angular/Http';
import { StatusBar, Splashscreen, OneSignal, Network, CodePush, SyncStatus } from 'ionic-native';
import { TabsPage } from '../pages/tabs/tabs';
import { EventsPage } from '../pages/events/events';
import { NewsPage } from '../pages/news/news';
import { RadioPage } from '../pages/radio/radio';
import { GalleryPage } from '../pages/gallery/gallery';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/fromEvent';
declare var navigator: any;
declare var Connection: any;
@Component({
templateUrl: 'app.html'
})
export class MyApp {
rootPage = TabsPage;
constructor(public platform: Platform, public alert: AlertController,
private events: Events,
public radioService: RadioPage,
private codePush: CodePush,
private ngZone: NgZone,
public http:Http) { }
ngOnInit() {
this.platform.ready().then(() => {
// My custom code
});
}
}
You should use import { Response, Http } from '@angular/http';
您应该使用
import { Response, Http } from '@angular/http';
in your component and service. 在您的组件和服务中。
and as you posted above you are missing import { HttpModule } from '@angular/http';
正如您在上方发布的,您缺少
import { HttpModule } from '@angular/http';
EDIT: 编辑:
Update your package.json to match the following dependencies, remove the existing node_modules directory, and then run npm instalL. 更新您的package.json以匹配以下依赖项,删除现有的node_modules目录,然后运行npm instalL。 Check this
link
. 检查此
link
。
You should remove 你应该删除
providers: [Http]
from your component annotation. 从您的组件注释中。
And '@angular/Http'
needs to be in lowercase, '@angular/http'
并且
'@angular/Http'
必须小写, '@angular/http'
好像您错过了导入HttpModule一样。
import { HttpModule } from '@angular/http';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.