I have the following code: (I've tried many ways)
performLogin = (data: LoginRequest) => {
var deferred = this.qService.defer();
var response = this.httpService.get(
myServiceURL + '&' + ObjecttoParams(data))
.then(function (response) {
debugger;
this.loginResponse = JSON.parse(JSON.stringify(response.data));
});
debugger;
deferred.resolve(response);
debugger;
return(this.loginResponse);
}
This is my constructor for this service:
constructor($http: ng.IHttpService, $location: ng.ILocationService, $q: ng.IQService) {
this.qService = $q;
this.httpService = $http;
this.locationService = $location;
this.loginResponse = new LoginResponse();
this.serviceURL = staticURL + currentServiceName;
}
I'm calling to performLogin in my controller, who expect to receive a "LoginResponse" class, but because the .then() is happening later, my "return this.loginResponse) happens before the .then() is even called.
How to I make him wait for the .then() to complete before returning?