You cannot get a simple http service to work in angular2. For some reason, I just get 404. It does not contain any functions yet, but it seems to me that DI is not working.
As soon as I add TestService when the application loads, I get the following. GET http://127.0.0.1:8080/testService 404 (not found)
index.html
<!DOCTYPE html> <html lang="en-GB"> <head> <title>AngularJS 2 Tutorial Series</title> <script src="https://code.angularjs.org/2.0.0-beta.0/angular2-polyfills.js"></script> <script src="https://code.angularjs.org/tools/system.js"></script> <script src="https://code.angularjs.org/tools/typescript.js"></script> <script src="https://code.angularjs.org/2.0.0-beta.1/Rx.js"></script> <script src="https://code.angularjs.org/2.0.0-beta.1/angular2.dev.js"></script> <script> System.config({ transpiler: 'typescript', typescriptOptions: { emitDecoratorMetadata: true } }); System.import('./app/app.ts'); </script> </head> <body> <my-app>loading...</my-app> </body> </html>
app.ts
import {bootstrap} from 'angular2/platform/browser'; import {Component} from 'angular2/core'; import {Injectable} from 'angular2/core' import {TestService} from 'testService'; @Component({ selector: 'my-app', template: '<h1>My First Angular 2 App</h1>', }) class AppComponent { } bootstrap(AppComponent, [TestService]);
TestService.ts
import {Http} from 'angular2/http'; import {Injectable} from 'angular2/core'; @Injectable() export class TestService { constructor(public http: Http){ } }
source share