0

I am new to Ionic framework and 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:

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

1 Answer 1

1

I checked one of my Ionic 2 projects and your imports should be

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

check your package.json and fix your project dependencies. You could use this project for references

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.