AngularJS $ httpBackend - [否更多的要求和期望QUOT;错误 [英] AngularJS $httpBackend - "No more request expected" error

查看:159
本文介绍了AngularJS $ httpBackend - [否更多的要求和期望QUOT;错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎是工作的解决方案,展示了如何使用 $ httpBacked http://jsfiddle.net/EgMpe/8/

It seems this is working solution that shows how to work with $httpBacked http://jsfiddle.net/EgMpe/8/

但是,对于我的情况:

路线

app.config(['$routeProvider', function($routeProvider) { $routeProvider.

    when('/',  {templateUrl: 'partials/user-list.html'}).

...

伪造服务:

app.run(function($httpBackend) {

        var users = [{"id":1,"name":"bob","email":"bob@bobs.com"}, {"id":2,"name":"bob2","email":"bob2@bobs.com"}]

        $httpBackend.whenGET('/rest/users').respond(function(method,url,data) {
            console.log("Getting users");
            return [200, users, {}];
        });
    });

..

真正的服务:

services.factory('Users', function($resource){
    return $resource('/rest/users', {}, {
        get:        {method: 'GET', isArray:true}
    });
});

我的错误时,去我的/路由重定向我用户list.html 页:

I have error when go to my "/" route that redirects me to user-list.html page:

错误:意外的请求:GET谐音/用户list.html无更多要求
  预期
      在$ httpBackend ... / mysite的/公/角/库/角1.2.0 /角mocks.js:1060:9)

Error: Unexpected request: GET partials/user-list.html No more request expected at $httpBackend .../mysite/public/angular/libs/angular-1.2.0/angular-mocks.js:1060:9)

问题1:确实 httpBackend prevent做任何其他 HTTP 的要求吗?

Question1: Does httpBackend prevent doing any other http request?

我试图使用直通方法,让HTTP打真正的服务器端:

I tried to use passThrough method to let http hit real server side:

$httpBackend.whenGET(/^\/mysite\//).passThrough();

但是,这并不能帮助。

But this does not help.

问题2:

推荐答案

啊..对不起,我只是错了我的正则表达式:

Ah.. Sorry I just was wrong with my RegEx:

如果此类型 $ httpBackend.whenGET(/谐音/)直通();

然后,所有开始工作。

所以,我得到了我的教训:不要忘了把:直通(); 正则表达式

So, I got my lesson: don't forget to put: passThrough(); with right RegEx.

这篇关于AngularJS $ httpBackend - [否更多的要求和期望QUOT;错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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