我已在HttpModule
中添加了import
,如下所示
app.module.ts
import { HttpModule, Http, XHRBackend, RequestOptions } from '@angular/Http';
import { ApiService } from '../services/api.service';
@NgModule({
imports: [
BrowserModule,
HttpModule,
.........
]
providers: [
ApiService,
.......
]
})
ApiService是我的自定义服务。
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
});
}
}
答案 0 :(得分:2)
您应该在组件和服务中使用import { Response, Http } from '@angular/http';
。
如上所述,您遗漏了import { HttpModule } from '@angular/http';
修改强>
更新package.json以匹配以下依赖项,删除现有的node_modules目录,然后运行npm instalL。请检查 link
。
答案 1 :(得分:2)
你应该删除
providers: [Http]
来自组件注释。
'@angular/Http'
需要小写,'@angular/http'
答案 2 :(得分:0)
好像你错过了导入HttpModule。
import { HttpModule } from '@angular/http';