I am a beginner with Angular and I am looking to invoke a service method within the authguard service. The specific service function that I need is as follows. Please note that I do not want to make any changes to this service function.
loadOrganizations() {
this.getOrganizations().subscribe(
(results) => {
const organizationList = [];
if (results.organizations) {
results.organizations.forEach((element) => {
this.appendOrganization(element, organizationList);
this.loadChildrenOrganization(element.children, organizationList);
});
}
this.organizations$.next(organizationList);
this.organizations$.complete();
},
(error) => {
this.organizations$.next([]);
this.organizations$.complete();
}
);
}
The calling method in my authguard TypeScript file is shown below.
canActivate(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot
): Promise<boolean> {
this.appService.loadOrganizations().then((answer: boolean) => {
return answer;
});
}
I encountered a return type error with "Promise" and "then". Any suggestions on how I can properly call this service method within the authguard service?