I am facing an issue with handling a HTTP GET request to retrieve permission data. This request is used in my auth.service.ts file within the isProjectLead() function. I need to ensure that access to a certain page is granted only after the HTTP request has returned the necessary value.
Can anyone suggest how I can achieve this? I attempted using Promises, but I lack expertise in this area.
get isProjectLead() {
var flag = false;
//var thisPromiseCount = ++this.promiseCount;
var user = JSON.parse(localStorage.getItem("user"));
if (!this.selectedProject) {
this.selectedProject = parseInt(this.route.snapshot.paramMap.get('id'));
}
this.linkService.getLinksByUserAndProject(user.username, this.selectedProject).subscribe(links => {
this.links = links;
this.links.forEach(element => {
if (JSON.parse(element).role.id == "2") {
flag = true;
}
});
},
(err: any) => {
});
return flag;
}