angular - 在 api 请求角度中添加变量
问题描述
我有一个以 id 作为参数的函数并执行以下操作:
onChooseVehicle(id){
console.log(id);
this.router.navigate(['tracking/v/-- id must be here --/live'])
}
id 的输出:4
这意味着我已成功接收数据,我如何将这个 id 放在 url 中?
this.router.navigate(['tracking/v/ --HERE -- /live'])
解决方案
您可以使用模板文字
this.router.navigate([`tracking/v/${id}/live`]); // notice the back ticks `` instead of quotes ''
或字符串连接
this.router.navigate(['tracking/v/' + id + '/live']); // here using quotes ''
你不能混合它们。
推荐阅读
- php - 如何使用 Laravel(Eloquent 的)地图收集功能重构 php foreach
- vhdl - if 语句的正确嵌套
- python - pygame相机没有关闭
- node.js - 无法获取,nodejs
- java - 使用 junit5 以编程方式运行测试
- php - PHP - 使用 sql 结果填充多维数组,指定键以聚合相似结果
- amazon-web-services - AWS Athena 部署无服务器框架
- winforms - 在已经绘制的自定义控件上绘制
- google-apps-script - 谷歌表格 - 填充单元格 A37 后,需要自动跳转到单元格 E9
- php - 降价供应商文件对可邮寄物品有什么作用?