Ionic2/Angular2 Http 不工作

Ionic2/Angular2 Http is not working

我是 Ionic 框架和 Angular2 的新手。我无法向服务器发送 post 请求。我不知道我错过了什么。

我的应用代码:

import { Component } from '@angular/core';

import { NavController } from 'ionic-angular';
import {Camera} from 'ionic-native';
import { Http, Headers, HTTP_PROVIDERS } from 'angular2/http';
import 'rxjs/Rx';

@Component({
  selector: 'page-upload',
  templateUrl: 'upload.html'
})
export class UploadPage {
  public base64Image: string;
  array = Array<any>;
  loading: boolean;
  constructor(public navCtrl: NavController,public http: Http) {

  }

  takePicture(){
    Camera.getPicture({
      destinationType: Camera.DestinationType.DATA_URL,
      targetWidth: 1000,
      targetHeight: 1000
    }).then((imageData) => {
      // imageData is a base64 encoded string
      this.base64Image = "data:image/jpeg;base64," + imageData;
    }, (err) => {
      console.log(err);
    });
  }


  accessGallery(){
    Camera.getPicture({
      sourceType: Camera.PictureSourceType.SAVEDPHOTOALBUM,
      destinationType: Camera.DestinationType.DATA_URL
    }).then((imageData) => {
      this.base64Image = 'data:image/jpeg;base64,'+imageData;
    }, (err) => {
      console.log(err);
    });
  }

  makePostRequest() {
    this.http.get('https://public-api.wordpress.com/rest/v1.1/freshly-pressed/').subscribe(data => {

    });
  }

}

当我为 android 编译应用程序时,出现以下错误:

 L16:    constructor(public navCtrl: NavController,public http: Http) {
  Cannot find name 'Http'.

我检查了我的一个 Ionic 2 项目,你的导入应该是

import {Http, Headers, RequestOptions, Response} from '@angular/http';

检查您的 package.json 并修复您的项目依赖项。您可以使用此项目作为参考

https://github.com/driftyco/ionic-conference-app/blob/master/package.json