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)
I have looked up tutorials and they include angular2/http the same way. Does anyone see what is going wrong?
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>
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With