This is a bug! In v1.8 - this bug is fixed!
I create issue in TypeScript repository: https://github.com/Microsoft/TypeScript/issues/7616
Problem:
I create simple class: defs.ts
export class default_config {
token:string
}
export var HEROES:default_config = {
token: 'a'
};
export class HeroService {
getHeroes() {
return HEROES;
}
setToken(key) {
HEROES.token = key;
}
}
And import to app.ts:
//our root app component
import {Component} from 'angular2/core'
import {Http, HTTP_PROVIDERS} from 'angular2/http';
import {RouteConfig, ROUTER_DIRECTIVES} from "angular2/router";
import {Headers} from "angular2/http";
import {HeroService} from "./defs";
@Component({
selector: 'my-app',
providers: [HTTP_PROVIDERS, HeroService],
template: `
<div>
<h2>Hello1 {{name}}</h2>
<br>
<router-outlet></router-outlet>
</div>
`
directives: [ROUTER_DIRECTIVES]
})
export class App {
constructor(private http:Http, serv: HeroService) {
this.name = 'Angular2';
var heads = new Headers();
console.log(heads);
}
}
But in console I have error: TypeError: http_2.Headers is not a constructor
Why? Why http_2? Why headers?...
When I this code:
import {Headers} from "angular2/http";
import {HeroService} from "./defs";
replace to this:
import {HeroService} from "./defs";
import {Headers} from "angular2/http";
all working fine! But I can not understand why I have this error?
Live demo: http://plnkr.co/edit/nfqjRyktqnscwUc6stbY?p=preview
It seems that you should use:
import {Headers} from 'angular2/http';
instead of
import {Headers} from "angular2/http";
See this plunkr: http://plnkr.co/edit/Eda5ypYUcn1N5XNM0FEM?p=preview.