Angular 2 http 模块加载问题 [英] Angular 2 http module load issue
问题描述
我正在尝试将 Angular1 应用程序重写为 Angular 2 应用程序.我在 angular-cli 的帮助下开始了这个新项目,但我无法导入 http 服务.
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.
我在 main.ts 中添加了以下行
I added the following line in my main.ts
import { HTTP_PROVIDERS } from '@angular/http';
我服务中的这个需要使用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.
推荐答案
你需要 index.html 中的这个文件来加载这些模块 :-
you need this file in index.html to load those modules :-
<script src="node_modules/angular2/bundles/http.dev.js"></script>
或
<script src="node_modules/angular2/bundles/http.js"></script>
模块中的任何一个
-
如果您在开发模式下使用测试版,我认为您只需要链接第一个文件.尽管两个文件都存在
I think you need to link only the first file if you using beta in dev mode.both files are present though
这篇关于Angular 2 http 模块加载问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!