Angular 2 http 模块加载问题 [英] Angular 2 http module load issue

查看:23
本文介绍了Angular 2 http 模块加载问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆