Within my LoginProvider, I have implemented a function that handles the login process and returns the session created as a promise.
@Injectable()
export class LoginProvider {
constructor(public http: HttpClient) { };
public async login(credentials: ICredentials): Promise<ISession> {
let url: string = "https:/url/to/login";
let headers: HttpHeaders = new HttpHeaders()
let params: HttpParams = new HttpParams()
.append("username", credentials.id)
.append("password", credentials.password);
return new Promise<ISession>((resolve, reject) => {
this.http.get(url, { headers: headers, params: params }).subscribe((response: ILoginResponse) => {
// handle response and return session
}, (error: HttpErrorResponse) => {
reject(error);
})
});
}
}
The issue arises when attempting to call this method because this.http
is somehow undefined. An error message stating ""_this.http is undefined"
" is displayed.
I am puzzled as to why http
would be undefined within this function. It is declared in the constructor, so it should be accessible for use in this particular function, right?