AuthHttp Not working in request
pankajk2934 opened this issue · comments
pankajk2934 commented
public login(username, password) {
let headers = new Headers();
headers.append('Content-Type', 'application/json; charset=UTF-8');
return this._authHttp
.post(
this._globalService.apiHost + '/user/login',
JSON.stringify({
"LoginForm": {
"username": username,
"password": password
}
}),
{headers: headers}
)
.map(response => response.json())
.map((response) => {
if (response.success) {
localStorage.setItem('frontend-token', response.data.access_token);
this.loggedIn = true;
} else {
localStorage.removeItem('frontend-token');
this.loggedIn = false;
}
return response;
})
.catch(this.handleError);
}
In this code authhttp not working when i replace authhttp to http it's working fine
can you please tell what is the processor of angular-jwt ?
Chris Lee commented
Hi @pankajk2934,
_authHttp:AuthHttp
must be defined in constructor()
and imported from 'angular2-jwt'
.
The code snippet for import angular2-jwt
:
import {AuthHttp, JwtHelper} from 'angular2-jwt';
The code snippet for constructor()
:
constructor(private _globalService: GlobalService,
private _router: Router,
private _authHttp: AuthHttp) {
this.loggedIn = this.isLoggedIn();
}
If above code is present and still not working, then can you provide full code?
And what is the error message?