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

$httpBackend(angularJS)中的URL参数

发布时间:2020-12-17 07:11:37 所属栏目:安全 来源:网络整理
导读:是否可以在angularJS的$httpBackend中接收URL参数?我想做的事情如下: $httpBackend.whenGET('/api/v1/users/{userId}').respond(function (method,url,data) { // somehow read {userId} and act differently depending on what the value is return [200]
是否可以在angularJS的$httpBackend中接收URL参数?我想做的事情如下:

$httpBackend.whenGET('/api/v1/users/{userId}').respond(function (method,url,data) {
    // somehow read {userId} and act differently depending on what the value is

    return [200];
});

拥有这个功能真的可以很容易地创建一个功能相当的模拟API(更容易开发前端应用程序而无需运行整个后端).

解决方法

您可以传递正则表达式而不是字符串作为URL.在回调函数中,从URL中提取userId,并回答您想要的内容.

(编辑:李大同)

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

    推荐文章
      热点阅读