TypeError: Cannot read property 'post' of undefined
This is happening when we generate an app in production. In development mode, everything works perfectly. Only in production mode http.post is not defined.
import { Injectable } from '@angular/core';
import { Headers, ResponseOptions} from '@angular/http';
import 'rxjs/add/operator/map';
import {JwtCredentials} from '../login/jwt-credentials';
import {Observable} from 'rxjs/Observable';
import { MEAT_API } from '../app.api';
import { AuthHttp, JwtHelper } from 'angular2-jwt';
@Injectable()
export class JwtCliente {
private _token = null;
private _payload = null;
constructor(public http: AuthHttp, public jwtHelper: JwtHelper) { }
assessToken(jwtCredentials: JwtCredentials): Observable<any> {
const headers = new Headers();
headers.append('Content-Type','application/json');
return this.http.post(`${MEAT_API}api-token-verify/`, jwtCredentials,
new ResponseOptions({headers: headers}))
.map((response) => {
let token = response.json().token;
this._token = token;
localStorage.setItem('token', this._token);
return token;
});
}
}
vendor.2a1591e60e00b8e65016.bundle.js:1 ERROR TypeError: Cannot read property 'post' of undefined at l.assessToken (main.951fcf271be890a69879.bundle.js:1) at l.Ct5P.l.login (main.951fcf271be890a69879.bundle.js:1) at l.K181.l.login (main.951fcf271be890a69879.bundle.js:1) at Object.handleEvent (main.951fcf271be890a69879.bundle.js:1) at Object._ [as handleEvent] (vendor.2a1591e60e00b8e65016.bundle.js:1) at Object.handleEvent (vendor.2a1591e60e00b8e65016.bundle.js:1) at ie (vendor.2a1591e60e00b8e65016.bundle.js:1) at vendor.2a1591e60e00b8e65016.bundle.js:1 at HTMLButtonElement. (vendor.2a1591e60e00b8e65016.bundle.js:1) at e.invokeTask (polyfills.939bb971810907071b8d.bundle.js:1)