This snippet of code is quite odd, but it resides within a service context:
constructor() {
gapi.load('client:auth2', this.loadGoogleApi);
}
private loadGoogleApi() {
// Array of API discovery doc URLs for APIs used by the quickstart
var DISCOVERY_DOCS = ["https://www.googleapis.com/discovery/v1/apis/calendar/v3/rest"];
// Authorization scopes required by the API; multiple scopes can be
// included, separated by spaces.
var SCOPES = "https://www.googleapis.com/auth/calendar.readonly";
//init google api
gapi.client.init({
apiKey: API_KEY,
clientId: CLIENT_ID,
discoveryDocs: DISCOVERY_DOCS,
scope: SCOPES
}).then(() => {
// Listen for sign-in state changes.
gapi.auth2.getAuthInstance().isSignedIn.listen(status => this.updateGoogleSigninStatus(status));
// Handle initial sign in state
this.updateGoogleSigninStatus(gapi.auth2.getAuthInstance().isSignedIn.get())
});
}
This block of code executes when the service is initialized. Surprisingly, the
status => this.updateGoogleSigninStatus(status)
function call works fine, but there is an issue with the subsequent line where the function seems to be inaccessible. An unusual scoping problem.
Cannot read property 'updateGoogleSigninStatus' of undefined
If I rearrange that line outside of the promise, everything functions correctly.