如何使用 get http 请求发送参数(id)?

Але*_*тић 1 get http angular

我开始打字,http.get 只接受 url,所以我不知道如何发送一个人的 id 以从我的 api 中获取该人,该人从 Sql 数据库中获取。

public getByID(n :number) : Promise<any>{

    return this.http.get(this.url).toPromise();
  }
Run Code Online (Sandbox Code Playgroud)

也许将它附加到一个网址?

Mic*_*oye 5

您可以选择使用模板字符串将参数添加到 URL

return this.http.get(`${this.url}?id=${n}`).toPromise();
Run Code Online (Sandbox Code Playgroud)