I need to call the following endpoint https://sample_url?id=12345 from an Angular service.
UserService
getUsersByGroupID(id): Observable<User[]> {
var url = 'https://sample_url';
var params = new HttpParams();
params = params.append('id', id);
this.data = this.http.get<User[]>(url, {params: params}, this.httpConfig.getHeaderOptions()).pipe(catchError(this.handleError('getData', [])));
return this.data;
}
In one of my components I should do something like...
this.userService.getUsersByGroupID(sys_id).toPromise().then(users => {
this.users = users as User[]
}
but i'm not sure how to include the query parameter ?id=correctly. I tried looking at How to pass url arguments (query string) to a HTTP request on Angular but didn't help much.
Thanks.
this.httpConfig.getHeaderOptions()is the header for the request, which is correct since I'm using it in another http request that does not require any parameter in the url