[英]Angular 2 gives SystemJS cannot find /angular2/http module
I have created a service for Angular 2: 我为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)
I have looked up tutorials and they include angular2/http the same way. 我查找了教程,它们以相同的方式包含angular2 / http。 Does anyone see what is going wrong? 有谁看到出了什么问题?
You need to check that you include the http.dev.js
file in your main HTML file: 您需要检查是否在主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>
You need then to add the HTTP_PROVIDERS as second parameter of the bootstrap function: 然后,您需要添加HTTP_PROVIDERS作为引导函数的第二个参数:
import { HTTP_PROVIDERS } from 'angular2/http';
bootstrap(MyMainComponent, [ HTTP_PROVIDERS ]);
Hope it helps you, Thierry 希望它对你有帮助,蒂埃里
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.