$ httpBackend与查询参数的要求 [英] $httpBackend with request with query param

查看:365
本文介绍了$ httpBackend与查询参数的要求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$httpBackend.whenGET('/restpath/api/v1/books')
.respond({// some data}); 

我收到以下错误

Error: Unexpected request: GET /restpath/api/v1/books
 Expected GET /restpath/api/v1/books?limit=10&start=1

对于expectGET我有以下内容,这将创建动态查询字符串。大多是开始的参数,和whenGET的一部分,我想服务器取决于开始

For the expectGET I have the following , and this creates dynamic query string. mostly the 'start' parameter, and the whenGET part, I am trying to server a dynamic content depending on the 'start'

$ httpBackend.expectGET('/ restpath / API / V1 /书籍限值为10安培;启动= 1');
 //实际的服务放在这里,它执行$ http服务。我们不关心
 $ httpBackend.flush();

推荐答案

如果你不关心你以后的参数?你可以这样做:

Hi if you dont care about the parameters after your '?' you can do this :

$httpBackend.expectGET(/.*?restpath\/api\/v1\/books?.*/g).respond(200, '{}');

如果你所关心的第一个参数做到这一点:

if you care about the first param do this :

$httpBackend.expectGET(/.*?restpath\/api\/v1\/books?limit=10.*/g).respond(200, '{}');

如果你关心他们都做到这一点:

if you care about them all do this :

$httpBackend.expectGET("/restpath/api/v1/books?limit=10&start=1").respond(200, '{}');

这篇关于$ httpBackend与查询参数的要求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆