我想以角度4打开用户个人资料页面: -
我从后端发送了Profile API: -
http://localhost:3001/my_profile/2.json/?api_token=Uq3cv0E4UukGRolYO3x4p-Zog7rnVqefj1uMGaq7EGA
然后我很困惑如何在服务中动态调用Userid(2)
doProfile(token: any){
let data = new URLSearchParams();
data.append('api_token', token);
return this.http.get(this.url+'my_profile/userId.json?'+'api_token='+token).map((response: Response) => response.json());
}
答案 0 :(得分:0)
将参数传递给doProfile
函数并使用它来形成网址,然后由于您已创建URLSearchParams
将其传递给params
选项的http
属性。
doProfile(token: any, userId: number){
let data = new URLSearchParams();
data.append('api_token', token);
return this.http.get(`${this.url}my_profile/${userId}.json`, {params: data })
.map((response: Response) => response.json());
}