2

Trying to get a Param from this url: /api/events/{id}

$httpBackend.whenGET(/\/api\/events\/(.+)/, undefined, undefined, ['eventID'])
               .respond(function(method, url, data, headers, params) {
                    console.log('get-params: ', params);
                    return 'test';
                });

Also this ist not working for me:

$httpBackend.when('GET', /\/api\/events\/(.+)/).respond...

as of AngularJS httpBackend Documentation (Dynamic responses) this should be working. Am I missing something, or is this a bug?

The Callback is called with the url like: "/api/events/1" but the params allways remain undefinded.

EDIT: This is to come in AngularJS Version 1.5.0

WayneJohn
  • 53
  • 6

1 Answers1

1

For AngularJS-Versions below 1.5.0 this might be a simple solution testing dynamic URL's with parameters:

$httpBackend.when('GET', /\/api\/events\/.+/)
                .respond(function(method, url, data, headers) {
                    var args = url.match(/\/api\/events\/(.+)/);
                    console.log('some Data', url, args);
                    console.log('First Arg: ', args[1]);
                    return args[1];
                });
WayneJohn
  • 53
  • 6