angularjs - $httpBackend (angularJS) 中的 URL 参数

标签 angularjs

是否可以在 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。在回调函数中,提取userId从 URL 中,然后回答您想要的内容。

关于angularjs - $httpBackend (angularJS) 中的 URL 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18011109/

相关文章:

javascript - 使用 Angular JS 删除 Facebook OAuth 哈希

javascript - Angular 在 localStorage 中存储日期值

javascript - orderBy 无法正常工作

javascript - 使用 BootStrap 和 Angular - 动态选择输入

angularjs - 在 AngularJS 中,为什么我不能在 src 旁边指定图像的宽度和高度?

angularjs - 自动对焦在某些条件后将启用的禁用字段

javascript - Angular js : Display an iframe in a pop up and see an empty frame

javascript - ng-options 在单击时清除模型(和可见选项),tarnation 是什么?

javascript - AngularJS ng-repeat 示例不起作用

html - 无法附加 AngularJS 数组