简体   繁体   English

Ionic2 / Angular2 Http无法正常工作

[英]Ionic2/Angular2 Http is not working

I am new to Ionic framework and Angular2. 我是Ionic Framework和Angular2的新手。 I am unable to send post request to the server. 我无法将发布请求发送到服务器。 I can't figure out what thing I am missing. 我不知道我缺少什么。

My App code: 我的应用程式码:

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

    });
  }

}

When I compile the app for android I get the following error: 当我为Android编译应用程序时,出现以下错误:

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

I checked one of my Ionic 2 projects and your imports should be 我检查了我的Ionic 2项目之一,您的进口货应该是

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

check your package.json and fix your project dependencies. 检查您的package.json并修复您的项目依赖项。 You could use this project for references 您可以将该项目用作参考

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM