Adding URL search parameters works a similar way. Here is a searchHeroes method that queries for heroes whose names contain the search term.
/* 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:newHttpParams().set('name', term) } : {}; return this.http.get<Hero[]>(this.heroesUrl, options) .pipe( catchError(this.handleError<Hero[]>('searchHeroes', [])) );}
If there is a search term, the code constructs an options object with an HTML URL-encoded search parameter. If the term were "foo", the GET request URL would be api/heroes/?name=foo.
The HttpParams are immutable so you'll have to use the set() method to update the options.