0

I need to pass queryParams (not route parameter) to an API endpoint using Resolver. How do you pass query parameter in component class and retrieve same in resolver? Please see my code snippets:

test.component.ts

loadTests(limit: number) {
this.route.data
   .subscribe(
     (data) => {
      this.tests  = data.tests;
     }
   );
}

test.resolver.ts

enter code here
  public resolve(
     route: ActivatedRouteSnapshot,
     state: RouterStateSnapshot
     ): Observable<ILaunch[]> {
    return this.testService.getAllTests(limit); // how do I retrieve 
        limit here from test component
       }

test.service.ts

public getAllTests( limit: number, ): Observable<ITest[]> {
return this.httpClient
  .get<ITestAPIData[]>(
    `${environment.baseUrl}tests?limit=${limit}}`
  )
  .pipe(map(data => (data)))
  .pipe(
    catchError())
  );
}

I have tried things like queryParams, params and switchMap but couldn't figure out how this should be implemented. Note: I don't want the query parameter to be passed to client routing url but API endpoint.

Any tip would be appreciated.

Thanks in advance

Nithya Rajan
  • 4,722
  • 19
  • 30
coa
  • 1
  • 2

0 Answers0