首页 > 解决方案 > 如何从 URL 获取字符串值?

问题描述

我的网址是http://localhost:4200/#/home/jobmanager/status

如何以字符串格式获取“状态”?我正在使用 TypeScript(.ts 文件)

例子:

this.getJobs("HERE");

“这里”是状态集

标签: angulartypescriptangular8

解决方案


像这样使用ActivatedRoute=>

this.activatedRoute.pathFromRoot[2].url.subscribe(mySegment=> console.log(mySegment[0].path));

pathFromRoot让你从所有的URL中选择你想要的段,你只需要在里面设置你想要的段[]


推荐阅读