After successfully implementing the gapi client in my Angular 2 app, I am now encounter an issue where my http object is undefined and I am not sure why.
Below is the code: constructor(private http: Http ) {}
initGmailApi() {
gapi.auth2.getAuthInstance().grantOfflineAccess().then(function(resp) {
console.log(resp);
const auth_code = resp.code;
const body = {'AuthCode': auth_code};
const headers = new Headers();
headers.append('Content-Type', 'application/json');
this.http.post('http://localhost:8080/startgmail', body, headers).subscribe(
(Response) => {
console.log(Response);
}
);
});
}
Basically what I am doing is requesting a permission from the user to access his gmail account and when I have a response I would like to pass some data received to my backend server.
If I am using this.http outside the "then" clause then the http method works fine however this create another issue where the "auth_code" value is not recognized.
What am I missing here?
function(resp)which is changing yourthisthe one you expect from the class. Use arrow function.