0

I'm trying to use the http module. After looking around for a bit I saw that the only two options for fixing this were to import the module (which i've done) or use HTTP_PROVIDERS which is deprecated for me.

I've imported it here:

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { HttpModule } from "@angular/http";
import { AppComponent } from './app.component';

@NgModule({
  imports: [BrowserModule, HttpModule],
  declarations: [AppComponent],
  bootstrap: [AppComponent]
})
export class AppModule { }

and this is my boot.ts

import 'core-js';
import 'zone.js/dist/zone';

import {bootstrap} from '@angular/platform-browser-dynamic';
import {ROUTER_PROVIDERS} from '@angular/router';
import {AppComponent} from './app.component';

bootstrap(AppComponent, [
  ROUTER_PROVIDERS
]);

And i'm trying to use it here :

import {Injectable} from '@angular/core';
import {Headers,Http} from '@angular/http';
@Injectable()
export class ApiService {
    constructor(private _http:Http){}

}

but for some reason It's giving me the error: EXCEPTION: Error: Uncaught (in promise): EXCEPTION: Error in :0:0 ORIGINAL EXCEPTION: No provider for Http!

The are the versions i'm using:

  "dependencies": {
    "@angular/common": "2.0.0-rc.1",
    "@angular/compiler": "2.0.0-rc.1",
    "@angular/core": "2.0.0-rc.1",
    "@angular/http": "^2.0.1",
    "@angular/platform-browser": "2.0.0-rc.1",
    "@angular/platform-browser-dynamic": "2.0.0-rc.1",
    "@angular/router": "2.0.0-rc.1",
    "es6-shim": "^0.35.0",
    "reflect-metadata": "0.1.3",
    "rxjs": "5.0.0-beta.6",
    "systemjs": "^0.19.27",
    "zone.js": "^0.6.12"
  },

any clue why I would still be getting this error after importing the module?

1
  • Is that a direct copy/paste from your package.json? @NgModule didn't exist until rc.5. You also have http: ^2.0.1 while the rest are rc.1. They aren't compatible. If this is a new project, just start with 2.0.1 across the board. Oct 2, 2016 at 21:06

1 Answer 1

0

If I remember correctly, NgModule was introduced in RC.5. But your dependencies is still using RC.1.

The current version of Angular2 is 2.0.1.

I will suggest following:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy