TypeError:无法读取属性' post'未定义的
当我们在生产中生成应用时会发生这种情况。在开发模式中,一切都很完美。仅在生产模式下,http.post未定义。
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:无法读取 物业&#39; post&#39;未定义的 在l.assessToken(main.951fcf271be890a69879.bundle.js:1) 在l.Ct5P.l.login(main.951fcf271be890a69879.bundle.js:1) 在l.K181.l.login(main.951fcf271be890a69879.bundle.js:1) 在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) 在vendor.2a1591e60e00b8e65016.bundle.js:1 在HTMLButtonElement。 (vendor.2a1591e60e00b8e65016.bundle.js:1) 在e.invokeTask(polyfills.939bb971810907071b8d.bundle.js:1)