我定义了一个像这样的URL URLT = URL/id/URL
如何将 id 的实际值放入“id”部分 (/id/)?
function(param: Param) {
return new Promise<boolean>( (resolve, reject) => {
this.http.post<boolean>(URLT+id, options).subscribe( (res => {
resolve(res);
}));
});
}
最佳答案
在 Javascript 中,您可以通过不同的方式创建该字符串,例如:
const myUrl = "http://www.api.com/" + id + "/foo"
或者更好的:
const myUrl = `http://www.api.com/${id}/foo`
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
干杯
关于javascript - 如何将 id 放在 url 中间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55889906/