Making HTTP requests -- "No provider for Http!" error


#1

So I have some pretty simple code for making a get request right now:

import {Injectable} from 'angular2/core';
import {Http} from 'angular2/http';

@Injectable()
export class HttpService {
    static get parameters() {
        return [[Http]];
    }
    constructor(http) {
        this.http = http;
    }

makeGetRequest() {
        this.http.get("http://httpbin.org/ip").subscribe(data => {
            alert(data.json().origin);
        }, error => {
            alert("Error");
        });
    }
}

which won’t even load the app because I get the error

2     087280   error    EXCEPTION: Error: Uncaught (in promise): EXCEPTION: Error in :0:0
ORIGINAL EXCEPTION: No provider for Http!

What step am I missing here?


#2

What version of ionic-angular are you using?


#3

I’m using 2.0.0-beta.7


#4

Then you forgot to change your imports from “angular2/” to “@angular/”. Read the changelog.


#5

That fixed it! Thanks very much.