zoidbergi zoidbergi - 1 year ago 1293
AngularJS Question

Angular 2 No provider for Http

I am getting the

EXCEPTION: No provider for Http!
in my Angular 2. What am I doing wrong?

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

selector: 'greetings-ac-app2',
providers: [],
templateUrl: 'app/greetings-ac2.html',
directives: [NgFor, NgModel, NgIf, FORM_DIRECTIVES],
pipes: []
export class GreetingsAcApp2 {
private str:any;

constructor(http: Http) {

this.str = {str:'test'};

headers: new Headers({
'Content-Type': 'application/json'

Answer Source

here is the code example for @serj-sagan

HTTP_PROVIDERS have to be included to your boot.ts, app.ts or main.ts. (depends on your configuration)

the content of the boot.ts file will look like:

import {bootstrap}    from 'angular2/platform/browser'
import {HTTP_PROVIDERS} from 'angular2/http';
import {AppComponent} from './app.component'

bootstrap(AppComponent, [HTTP_PROVIDERS]);

Note: On newer versions of angular following works:

import {bootstrap}    from '@angular/platform/browser'
import {HTTP_PROVIDERS} from '@angular/http';
import {AppComponent} from './app.component'

bootstrap(AppComponent, [HTTP_PROVIDERS]);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download