当作为prod运行时,Angular2 this.http未定义.
发布时间:2020-12-17 17:00:39 所属栏目:安全 来源:网络整理
导读:我有一个像heroService这样的简单服务: import { Headers,Http } from '@angular/http';@Injectable()export class HeroService { constructor(private http: Http) { } getHeroes(): PromiseHero[] { return this.http.get(this.heroesUrl) .toPromise() .
我有一个像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,所以我不知道为什么它不知道它是什么. 有谁知道我是否遗漏了什么,或者这是一个错误? 解决方法
对于较新版本的角度,这不再是一个问题.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |