我有一个像heroService这样的简单服务:
import { Headers,Http } from '@angular/http'; @Injectable() export class HeroService { constructor(private http: Http) { } getHeroes(): Promise<Hero[]> { return this.http.get(this.heroesUrl) .toPromise() .then(response => response.json().data as Hero[]) .catch(this.handleError); }
它在运行ng服务时工作正常,但是如果我使用prod构建或运行“ng serve –prod”this.http是未定义的.我在我的应用程序上导入httpModule,所以我不知道为什么它不知道它是什么.
有谁知道我是否遗漏了什么,或者这是一个错误?
解决方法
对于较新版本的角度,这不再是一个问题.