加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 角度2给SystemJS找不到/ angular2/http模块

发布时间:2020-12-17 08:07:42 所属栏目:安全 来源:网络整理
导读:我为Angular 2创造了一个服务: import {Injectable} from "angular2/core";import {Http} from "angular2/http";import {TaskModel} from "./tasks.model"@Injectable()export class TasksDataService { tasks:Arrayany; constructor(http:Http) { this.tas
我为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;
  }
}

当我运行我的程序浏览器显示:

system.src.js:1049 GET http:// localhost:3000 / angular2 / http.js 404(未找到)

我已经看了教程,它们包括了相同的角度/ http。有谁看到出了什么问题?

您需要检查是否在主HTML文件中包含http.dev.js文件:
<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作为引导函数的第二个参数:

import { HTTP_PROVIDERS } from 'angular2/http';

bootstrap(MyMainComponent,[ HTTP_PROVIDERS ]);

希望它能帮助你,蒂埃里

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读