Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Angular 6在HTTP请求中包含参数_Angular_Http_Angular Services_Angular Httpclient - Fatal编程技术网

如何使用Angular 6在HTTP请求中包含参数

如何使用Angular 6在HTTP请求中包含参数,angular,http,angular-services,angular-httpclient,Angular,Http,Angular Services,Angular Httpclient,我需要调用以下端点https://sample_url?id=12345来自角度服务 用户服务 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, {par

我需要调用以下端点
https://sample_url?id=12345
来自角度服务

用户服务

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;
}
但是我不确定如何正确地包含查询参数
?id=
。我试着看了看,但没有多大帮助

谢谢。

getUsersByGroupID(id:number):可观察{
getUsersByGroupID(id: number): Observable<User[]> {
    return this.http.get<User[]>("https://sample_url?id=" + id)
        .pipe(
             map(response => {
                 return response;
    }));
}
返回此.http.get(“https://sample_url?id=“+id) .烟斗( 映射(响应=>{ 返回响应; })); }
getUsersByGroupID(id:number):可观察{
返回此.http.get(“https://sample_url?id=“+id)
.烟斗(
映射(响应=>{
返回响应;
}));
}

btw,
this.httpConfig.getHeaderOptions()
是请求的标题,这是正确的,因为我正在另一个不需要URL中任何参数的http请求中使用它。为什么不阅读文档。get()需要2个参数,而不是3.btw,
this.httpConfig.getHeaderOptions()
是请求的头,这是正确的,因为我正在另一个不需要URL中任何参数的http请求中使用它为什么不简单地阅读文档。get()需要2个参数,而不是3个。您可以在答案中添加一些描述来解释您所做的更改。您可以在答案中添加一些描述来解释您所做的更改。
getUsersByGroupID(id: number): Observable<User[]> {
    return this.http.get<User[]>("https://sample_url?id=" + id)
        .pipe(
             map(response => {
                 return response;
    }));
}