angular - 如何从 URL 获取字符串值?
问题描述
我的网址是http://localhost:4200/#/home/jobmanager/status
如何以字符串格式获取“状态”?我正在使用 TypeScript(.ts 文件)
例子:
this.getJobs("HERE");
“这里”是状态集
解决方案
像这样使用ActivatedRoute
=>
this.activatedRoute.pathFromRoot[2].url.subscribe(mySegment=> console.log(mySegment[0].path));
pathFromRoot
让你从所有的URL中选择你想要的段,你只需要在里面设置你想要的段[]
推荐阅读
- pygears - 如何在 pyGears 框架中使用 GearBox?
- r - 救命!计算每个子组的比例
- wordpress - AMP 验证错误属性“值”可能不会出现在标记“元”中
- node.js - Mongoose .find({}) 返回空数组
- c# - 使用 WebApplicationFactory 运行集成测试会抛出 CancellationTokenSource 已在测试类清理中处理
- mediawiki-templates - Semantic Mediawiki 模板中使用的属性数量是否有限制?
- amazon-web-services - 错误:“主题不存在”使用 SAM 模板创建 SNS 主题?
- kdb - 如何构建投影的解析树?
- php - 如何安全地验证 iframe 中的跨域(不包括第三方 cookie)?
- api - 嵌入谷歌搜索数据