Angular 2 HTTP模块不通过system.js加载:错误:找不到名称' Http'

时间:2015-12-16 22:23:17

标签: angular

Angular最新beta.0错误:错误:(15,25)TS2304:找不到姓名' Http'。 试过像

这样的差异
import {Http} from 'angular2/core';
import {Http} from 'angular2/core';
import {Http} from 'angular2/http.dev';
import {Http} from 'angular2/bundles/http';
一切都没有运气:(

这是我的组件:

  ///<reference path="../../typings/es6-promise/es6-promise.d.ts"/>
///<reference path="../../typings/zone.js/zone.js.d.ts"/>

import {Component} from 'angular2/core';
import {Injectable} from 'angular2/core';
import {Inject} from 'angular2/core';
import {HTTP_PROVIDERS, Http} from 'angular2/http';

@Component({
    providers: [HTTP_PROVIDERS]
})

@Injectable()
export class MyService {
    private _val:number;

    constructor(@Inject(Http) http:Http) {
        this._val = Math.random();
    }

    public showAlert() {
        alert(`here is an alert ${this._val}`);
    }
}

1 个答案:

答案 0 :(得分:0)

从ng2 beta开始需要将我的system.js更改为

 <script>
System.config({
  defaultJSExtensions: true,
  transpiler: 'typescript',
  packages: {
    'component': {defaultExtension: 'ts'}
  },
  typescriptOptions: {emitDecoratorMetadata: true}
});
System.import('./component/App.ts')

希望它可以帮助某人...