Ionic2 / Angular2 Http无效

时间:2017-02-25 17:52:00

标签: android cordova http ionic-framework phonegap-build

我是Ionic框架和Angular2的新手。我无法将post请求发送到服务器。我无法弄清楚我错过了什么。

我的应用代码:

npm install express

当我为Android编译应用程序时,我收到以下错误:

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 => {

    });
  }

}

1 个答案:

答案 0 :(得分:1)

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

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

检查你的package.json并修复你的项目依赖项。您可以将此项目用于参考

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