Angular 2 http module load issue

﹥>﹥吖頭↗ 提交于 2019-12-12 03:09:46

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/37088713/angular-2-http-module-load-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!