i want to make a function that returns a token from a server but http.post() gets a response after my function returned the token.
How do i wait for http.post() before returning the token.
My code:
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
@Injectable()
export class ServerConnectionService{
constructor( private http : Http) { }
token : string;
Login(Password : string, Username : string, ServerRootURL : string) : string
{
let url = ServerRootURL + "api/AdminApp/RegisterToken";
this.http.post(url, { "Username": Username, "Password": Password }).toPromise()
.then(res => this.token = res.json())
.catch(msg => console.log('Error: ' + msg.status + ' ' + msg.statusText))
return this.token;
}
}
Thank you in advance.