ses ses - 2 months ago 10
AngularJS Question

AngularJS $httpBackend - "No more request expected" error

It seems this is working solution that shows how to work with

$httpBacked
http://jsfiddle.net/EgMpe/8/

But for my case:

routes

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

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


...

faked service:

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, {}];
});
});


..

real service:

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


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


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)


Question1: Does
httpBackend
prevent doing any other
http
request?

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

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


But this does not help.

ses ses
Answer

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

if type this $httpBackend.whenGET(/partials/).passThrough();

Then all start working.

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