【发布时间】:2020-04-17 09:38:05
【问题描述】:
有什么方法可以从我的 Angular 服务中的任何特定 URL 获取 GET URL 查询字符串参数?
例如假设我有一个 URL = "http:localhost/?id=123&name=abc"; 或 URL = "http://www.myexamplewebsite.com?id=123&name=abc";
// in my service.ts
public myFunction(): Observale<any>
{
let getVariable= this.http.get(URL);
return getVariable.pipe(map(response => <Object>response), catchError(error => this.handleError(error)));
}
那么在我的 component.ts 或 service.ts 中,有什么方法可以提取此 ID 和名称吗?我是这个话题的新手。
注意:我没有在我的路由中运行该 URL。所以 this.route.snap.params 函数没有帮助。
【问题讨论】:
-
你有没有在这段代码中使用过角度路由器?
标签: javascript node.js angular typescript