Angular 2使SystemJS找不到/angular2/http模块 [英] Angular 2 gives SystemJS cannot find /angular2/http module

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

问题描述

我已经为Angular 2创建了服务:

I have created a service for Angular 2:

import {Injectable} from "angular2/core";
import {Http} from "angular2/http";
import {TaskModel} from "./tasks.model"

@Injectable()
export class TasksDataService {

  tasks:Array<any>;

  constructor(http:Http) {

    this.tasks = [
      new TaskModel("Dishes"),
      new TaskModel("Cleaning the garage"),
      new TaskModel("Mow the grass")
    ];
  }

  getTasks():Array<any> {
    return this.tasks;
  }
}

运行程序时,浏览器显示:

When I run my program the browser shows:

system.src.js:1049 GET http://localhost:3000/angular2/http.js 404 (Not Found)

system.src.js:1049 GET http://localhost:3000/angular2/http.js 404 (Not Found)

我看过教程,它们以相同的方式包含angular2/http.有人看到出什么问题了吗?

I have looked up tutorials and they include angular2/http the same way. Does anyone see what is going wrong?

推荐答案

您需要检查主HTML文件中是否包含http.dev.js文件

You need to check that you include the http.dev.js file in your main HTML file:

<script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="node_modules/rxjs/bundles/Rx.js"></script>
<script src="node_modules/angular2/bundles/angular2.dev.js"></script>
<script src="node_modules/angular2/bundles/router.dev.js"></script>
<script src="node_modules/angular2/bundles/http.dev.js"></script>

然后,您需要添加HTTP_PROVIDERS作为引导程序功能的第二个参数:

You need then to add the HTTP_PROVIDERS as second parameter of the bootstrap function:

import { HTTP_PROVIDERS } from 'angular2/http';

bootstrap(MyMainComponent, [ HTTP_PROVIDERS ]);

希望它对您有帮助, 蒂埃里

Hope it helps you, Thierry

这篇关于Angular 2使SystemJS找不到/angular2/http模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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