Can someone help me with defining the http client
? I am having issues with this.http.post
not functioning correctly. My goal is to send a post request in order to receive a jwt key response from an API endpoint.
import { Inject, Injectable } from '@angular/core';
import { BROWSER_STORAGE } from './storage';
import { User } from './user';
import { Authresponse } from './authresponse';
import { HttpClient } from '@angular/common/http';
@Injectable({
providedIn: 'root'
})
let http = new HttpClient;
export class AuthenticationService {
constructor(@Inject(BROWSER_STORAGE) private storage: Storage) { }
public getToken(): String | null {
return this.storage.getItem('token1');
}
public saveToken(token: string): void {
this.storage.setItem('token1', token);
}
public login(email:string, password:string ) {
return this.http.post<User>('http://localhost:3000/login', {email, password})
.then((authResp: Authresponse) => this.saveToken(authResp.token));
}