Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot find module '@angular/http'?

Tags:

angular

I added the following property to my systemjs.config.js map object in my Angular 2 app:

'@angular/http': 'https://npmcdn.com/@angular/http' 

When I ctrl-click on the url it attempts to download a js file. However, when I try to import from '@angular/http' at the top of my service.ts, the compiler returns the error "Cannot find module '@angular/http'.`"

Is there an additional step that I'm missing in order for this module to be recognized and usable by my angular app? I'm using Angular version 2.0.0-rc.4.

like image 704
user6604655 Avatar asked Jul 21 '16 17:07

user6604655


People also ask

Can not find module error in angular?

To solve the error "Cannot find module '@angular/core'", make sure you have installed all dependencies by running the npm install command, set the baseUrl option to src in your tsconfig. json file and restart your IDE and development server.

What is HTTP module in angular?

Angular provides a client HTTP API for Angular applications, the HttpClient service class in @angular/common/http . The HTTP client service offers the following major features. The ability to request typed response objects. Streamlined error handling. Testability features.

What is the difference between HTTP and HttpClient in angular?

The HttpClient is used to perform HTTP requests and it imported form @angular/common/http. The HttpClient is more modern and easy to use the alternative of HTTP. HttpClient is an improved replacement for Http. They expect to deprecate Http in Angular 5 and remove it in a later version.


1 Answers

run this in terminal:

npm install @angular/http@latest 

Update for Angular 5+ versions:

import {HttpClientModule} from '@angular/common/http' import {HttpClient} from '@angular/common/http' 

instead of HttpModule and Http respectively.

like image 87
Rohit Bagjani Avatar answered Sep 28 '22 05:09

Rohit Bagjani