Question Details

No question body available.

Tags

angular rxjs angular-resolver angular19

Answers (2)

May 29, 2025 Score: 0 Rep: 66,494 Quality: Medium Completeness: 60%

Move the rest of the code inside the switchMap by chaining them to the result of the switchMap. Then we use a filter to allow the stream to emit only when the returned array of customersList$ has a length.

export const customerTitleResolver: ResolveFn = (route) => {
  const timesheetSelectionService = inject(TimesheetSelectionService);

const customerNumParam = route.paramMap.get('custNum') ?? ''; return timesheetSelectionService.customersList$.pipe( filter((list) => list?.length), // list.find((cust) => cust.id === customerNumParam)?.description ?? ''), ); };

OR

export const customerTitleResolver: ResolveFn = (route) => {
  const timesheetSelectionService = inject(TimesheetSelectionService);

const customerNumParam = route.paramMap.get('custNum') ?? ''; return timesheetSelectionService.isLoading$.pipe( filter((isLoading) => !isLoading), switchMap(() => timesheetSelectionService.customersList$.pipe( filter((list) => list?.length), // list.find((cust) => cust.id === customerNumParam)?.description ?? ''), )), ); };
May 29, 2025 Score: 0 Rep: 1 Quality: Low Completeness: 50%

I think the issue might be that you need a "finite" observable that completes after emitting value

so extending answer of Naren Murali, maybe adding take(1) after filter will help

export const customerTitleResolver: ResolveFn = (route) => {
  const timesheetSelectionService = inject(TimesheetSelectionService);

const customerNumParam = route.paramMap.get('custNum') ?? ''; return timesheetSelectionService.customersList$.pipe( filter((list) => list?.length), take(1), map((list) => list.find((cust) => cust.id === customerNumParam)?.description ?? ''), ); };