首页 > 解决方案 > 从返回的 URL 中获取参数

问题描述

我想使用这个打字稿解析 GET 请求的结果:

return this.httpClient
      .get('http://localhost:8080', options)
      .pipe(
        map((response: Response) => {
          console.log(response)
        })
      );

我想code从重定向的 http 响应中获取值:http://localhost:9000/callback?code=7CLwgh。我怎样才能获得价值?

标签: angulartypescriptangular9

解决方案


您可以使用拆分字符串

var str="http://localhost:9000/callback?code=7CLwgh";
var sp=str.split("code=");
console.log(sp[1]);

推荐阅读