Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2 gives SystemJS cannot find /angular2/http module

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?

like image 821
Bas van Dijk Avatar asked Jan 12 '16 15:01

Bas van Dijk


1 Answers

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

like image 160
Thierry Templier Avatar answered Oct 22 '22 01:10

Thierry Templier