加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

AngularJS |使用$http.get方法设置路径Parmeter

发布时间:2020-12-17 09:03:09 所属栏目:安全 来源:网络整理
导读:我有一个GET端点,URI为/ user / user-id. ‘user-id’是这里的路径变量. 在GET请求时如何设置路径变量? 这是我试过的: $http.get('/user/:id',{ params: {id:key} }); 而不是替换路径变量,id被附加为查询参数. 即我的调试器将请求URL显示为“http:// loca
我有一个GET端点,URI为/ user / user-id. ‘user-id’是这里的路径变量.

在GET请求时如何设置路径变量?

这是我试过的:

$http.get('/user/:id',{
                params: {id:key}
            });

而不是替换路径变量,id被附加为查询参数.
即我的调试器将请求URL显示为“http:// localhost:8080 / user /:id?id = test”

我的预期解决的网址应该是“http://localhost:8080/user/test”

$http的params对象用于查询字符串,因此您传递给参数的键值对将作为查询字符串键和值输出.
$http.get('/user',{
    params: { id: "test" }
});

成为:http:// localhost:8080 / user?id = test

如果您需要http:// localhost:8080 / user / test,您可以:

>自己构建url,

$http.get(‘/ user /’id);
>或者,使用$资源(特别是$resource.get https://docs.angularjs.org/api/ngResource/service/ $资源).这有点清洁.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读