gpt4 book ai didi

node.js - 在 ID 为 String 的 Angular 4 中使用路由参数

转载 作者:搜寻专家 更新时间:2023-11-01 00:38:03 27 4
gpt4 key购买 nike

如何使用ID为String的路由参数?

{path: 'param/:id', component: MyComponent}

let id = this.route.snapshot.params['id'];
任何想法

Blockquote

最佳答案

如您所示,使用路由快照获取 id 查询参数应该会给您一个字符串。如果您想将该字符串隐式转换为数字,以便在导航的路由参数中使用它,您可以在变量前加上 + 前缀:

// (+) converts string 'id' to a number
let id = +this.route.snapshot.params['id'];

然后:

this.router.navigate(['/example', id]);

查看文档中获取查询参数的示例 https://angular.io/guide/router#snapshot-the-no-observable-alternative .

关于node.js - 在 ID 为 String 的 Angular 4 中使用路由参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44603142/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com