I have encountered an issue while working with the Google API service and I am stuck at the promise response stage. Here is the code snippet for reference:
getPromise: Promise<any>;
loadSheets: Array<any>;
constructor(public _checkAuthApiService: CheckAuthApiService) { }
ngOnInit() {
if (this._checkAuthApiService) {
this._checkAuthApiService.checkAuth().then(res => {
if (res && !res.error) {
this.loadSheetsFunc();
}
});
}
//setTimeout(function(){},1000); //When i add this it works :(
}
loadSheetsFunc = () => {
this.getPromise = new Promise((resolve: any, reject: any) => {
resolve(this._checkAuthApiService.loadSheetsApi())
});
this.getPromise.then((res: any) => this.sheetsResults(res));
};
sheetsResults = (res: any) => this.loadSheets = res.result.values;
I am unsure about what is causing the issue, but interestingly, when I include a setTimeout
within the ngOnInit
function, the code starts working and I get the desired data on the view. Can someone provide assistance with this code, or even suggest a better approach using Observables? Thank you in advance.