if I create new class in Angular2 I have this error: TypeError: http_2.Headers is not a constructor
if I create new class in Angular2 I have this error: TypeError: http_2.Headers is not a constructor
这是一个错误!在 v1.8 中 - 此错误已修复!
我在 TypeScript 存储库中创建问题:https://github.com/Microsoft/TypeScript/issues/7616
问题:
我创建简单 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;
}
}
并导入到 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);
}
}
但是在控制台我有错误:TypeError: http_2.Headers is not a constructor
为什么?为什么 http_2?为什么 headers?...
当我这段代码时:
import {Headers} from "angular2/http";
import {HeroService} from "./defs";
替换为:
import {HeroService} from "./defs";
import {Headers} from "angular2/http";
一切正常!
但是我不明白为什么会出现这个错误?
看来你应该使用:
import {Headers} from 'angular2/http';
而不是
import {Headers} from "angular2/http";
看到这个 plunkr:http://plnkr.co/edit/Eda5ypYUcn1N5XNM0FEM?p=preview。
这是一个错误!在 v1.8 中 - 此错误已修复!
我在 TypeScript 存储库中创建问题:https://github.com/Microsoft/TypeScript/issues/7616
问题:
我创建简单 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;
}
}
并导入到 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);
}
}
但是在控制台我有错误:TypeError: http_2.Headers is not a constructor
为什么?为什么 http_2?为什么 headers?...
当我这段代码时:
import {Headers} from "angular2/http";
import {HeroService} from "./defs";
替换为:
import {HeroService} from "./defs";
import {Headers} from "angular2/http";
一切正常! 但是我不明白为什么会出现这个错误?
看来你应该使用:
import {Headers} from 'angular2/http';
而不是
import {Headers} from "angular2/http";
看到这个 plunkr:http://plnkr.co/edit/Eda5ypYUcn1N5XNM0FEM?p=preview。