Reputation: 1006
I use $httpBackend
in a backend-less development :
I have a module called FakeBackend injected in my application :
angular.module("FakeBackend", ["ngMockE2E"])
.run(function($httpBackend){
...
...
function myResponse() {
return "someting";
}
$httpBackend.whenGET("/api/myRoute").respond(myResponse());
$httpBackend.whenGET(/\/*/).passThrough();
});
I do my requests with $http normaly and i get the correct response from the mock. But now I want a dynamic response (for example /api/getTime and the service return a timestamp ) . For now, i only have one same response ( like if it was cached ) for all my requests. How I can do that? Is it possible?
Upvotes: 0
Views: 216
Reputation: 4611
you can respond with function and return your need eg .
$httpBackend.whenPOST('/api/getTime').respond(function () {
var timeStamp = new Date().getTime();
return [200, timeStamp];
});
Upvotes: 2