I'm trying to setup a simple @Injectable
called HttpApi
which I then use in app.ts
.
But I get following error:
No provider for Http! (AppComponent -> HttpApi -> Http)
Both TypeScript files are build with the following command:
tsc -m commonjs -t es5 --experimentalDecorators --emitDecoratorMetadata app.ts
I do understand the error but I have no clue on how to fix it. What am I overlooking?
index.html:
<!DOCTYPE html>
<html>
<head>
<script src="../node_modules/systemjs/dist/system.src.js"></script>
<script src="../node_modules/angular2/bundles/angular2.dev.js"></script>
<script src="../node_modules/angular2/bundles/http.dev.js"></script>
</head>
<body>
<app></app>
<script>
System.config({
map: {
httpApi: 'src/httpApi.js'
}
});
System.import('src/app.js');
</script>
</body>
</html>
httpApi.ts:
///<reference path="typings/angular2/angular2.d.ts"/>
///<reference path="typings/angular2/http.d.ts"/>
import {Injectable, bind} from 'angular2/angular2';
import {Http, Headers} from 'angular2/http';
@Injectable()
export class HttpApi {
constructor(public http: Http) {
}
public getChampions() {
return this.http.get('http://localhost:12345/champions')
.toRx()
.map(res => this.ResponseToArray(res));
}
}
app.ts:
/// <reference path="typings/angular2/angular2.d.ts" />
import {Component, View, bootstrap, Inject} from 'angular2/angular2';
import {HttpApi} from 'server';
@Component({
selector: 'app',
bindings: [HttpApi]
})
@View({
templateUrl: 'some.html'
})
class AppComponent {
champions: Object;
constructor(httpApi: HttpApi) {
httpApi.getChampions()
.subscribe(champions => this.champions = champions);
}
}
bootstrap(AppComponent, [HttpApi]);