URL Parameters with HttpClientModule in Angular

/* GET heroes whose name contains search term */
searchHeroes(term: string): Observable<Hero[]> {
  term = term.trim();

  // Add safe, URL encoded search parameter if there is a search term
  const options = term ?
   { params: new HttpParams().set('name', term) } : {};

  return this.http.get<Hero[]>(this.heroesUrl, options)
      catchError(this.handleError<Hero[]>('searchHeroes', []))


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.