Currently, I am diving into the world of RxJS. In my project, I am dealing with 2 different APIs where I need to fetch data from the first API and then make a call to the second API based on that data. Originally, I implemented this logic using the subscribe() method as shown below:
checkPermission(permissionName: string): Observable<boolean> {
this.checkCompanySettingForPermission(
this.pageLevelCompanySettingName
).subscribe(res => {
const shouldCheck = res.Value;
if (shouldCheck.toLowerCase() === "true") {
this.hasPermission(permissionName).subscribe(res => {
this.$permissionSub.next(res.permission);
});
} else {
this.$permissionSub.next(true);
}
});
return this.$permissionSub.asObservable();
}
However, I'm now looking for a way to avoid nesting subscribe() methods within each other. Is there any RxJS operator that can help me achieve this?
I attempted to use switchMap() but encountered numerous syntax errors in the process. Any guidance or assistance would be greatly appreciated.