0

I'm trying to start to rewrite an Angular1 app into Angular 2 app. I start this new project with th help of angular-cli but I'm block to import http service.

I added the following line in my main.ts

import { HTTP_PROVIDERS } from '@angular/http';

And this one in my service that need to use http

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

And for there two lines I have the following error:

Cannot find module '@angular/http'

Have you some Idea about what can i miss ? Thank you.

qchap
  • 345
  • 6
  • 17
  • most probably you are missing import of http file in index.html, also its good practice to import `HTTP_PROVIDERS` at the time of bootstrap your app. – Pardeep Jain May 07 '16 at 12:57

1 Answers1

0

you need this file in index.html to load those modules :-

<script src="node_modules/angular2/bundles/http.dev.js"></script>

or

<script src="node_modules/angular2/bundles/http.js"></script>

whichever is in your modules

EDIT :-

I think you need to link only the first file if you using beta in dev mode.both files are present though

UzUmAkI_NaRuTo
  • 565
  • 3
  • 8
  • 20
  • I try this but without result. I Check this example https://github.com/johnpapa/angular2-force and nothing like that in index.html. However I have no node_modules/angular2 in my project. There is only this folder: node_modules/@angular – qchap May 07 '16 at 12:58
  • 1
    on checking the config at your link https://github.com/johnpapa/angular2-force/blob/master/package.json its using angular 2 rc version.check if http module stated in package,json was installed successfully. anyways, i suggest you to use more stable beta version. rc is old now. check this repo :- https://github.com/mschwarzmueller/angular-2-introduction and this https://github.com/bapatel1/Learning-Angular-2.0 – UzUmAkI_NaRuTo May 07 '16 at 13:06
  • beta is old, rc is new. Match your configuration with [angular's quickstart guide](https://angular.io/docs/ts/latest/quickstart.html) – Ankit Singh May 07 '16 at 13:09
  • I'm ok with A_Singh rc have 4 day. But thank you Sumeet this is a package.json issue ! – qchap May 07 '16 at 13:13