AngularJS $ httpBackend - [否更多的要求和期望QUOT;错误 [英] AngularJS $httpBackend - "No more request expected" error
问题描述
这似乎这是工作的解决方案,展示了如何使用 $ httpBacked $ C工作$ C> 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屋!