I've encountered a problem that requires me to use a combination of 3 route observables to open a modal. Here is the logic in my code:
combineLatest([obs1, obs2, obs3])
.subscribe(([s1, s2, s3]: any) => {
openModal();
});
The issue I'm facing is that since this code gets executed 3 times, the modal opens three times as well, which is not the desired behavior.
To handle this, I resorted to a less than ideal solution by introducing a flag like so:
let shouldOpen = true;
combineLatest([obs1, obs2, obs3])
.subscribe(([s1, s2, s3]: any) => {
if(shouldOpen) {
shouldOpen = false;
openModal();
}
});
However, I am aware that this workaround is not optimal.
My question now is whether there is a way for me to continue using combineLatest but ensure that it is only executed once?
You can also check out this Stackblitz link to experiment with combineLatest.
Note: I have already tried and cannot use forkJoin or zip for this scenario.