I am encountering an issue with ngrx and my resolver in Angular. I have identified the problem but cannot find a solution for it. The issue arises when I select an account from my ngrx store and end the observable with take(1). Due to take(1), it always takes the first value. As a result, when I emit a new value, the resolver does not get it. Can anyone provide assistance?
resolve(route: ActivatedRouteSnapshot): Observable<Account> {
const id = this.getParameter(route, 'accountId');
if (id) {
this._store.dispatch(AccountsPageActions.loadAccountWithDetails({ accountId: id }));
return this._store.select(getAccountDetailById(id)).pipe(
switchMap(account => this._store.select(getAccountError).pipe(
map(error => {
if (error instanceof HttpErrorResponse && error.message.includes(id)) {
this._utilService.showErrorToast('Zugang nicht gefunden');
this._router.navigateByUrl('/');
}
console.log(account);
return account
})
)),
skipWhile(account => account?.id !== id),
take(1)
);
}
return null;
}
Edit: The problem is that I trigger the resolver in the same route. Example: I open an accordion item --> redirect to /account/{accountId1} and then when I open another accordion item, I need to redirect to /account/{accountId2}. However, the resolver fails to resolve because it does not receive a new value with the new account.