Angular2 this.http undefined when run as prod.

I have a simple service like 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);
   }

It works great when starting an ng service, however, if I create with prod or run "ng serve -prod" this.http undefined. I am importing httpModule into my application, so I donโ€™t know why it doesnโ€™t know what it is.

Does anyone know if I missed something, or is this a mistake?

+4
source share

Source: https://habr.com/ru/post/1669934/


All Articles