简体   繁体   English

AngularJs $ httpbackend.whenPOST正则表达式不起作用

[英]AngularJs $httpbackend.whenPOST regular expression not working

am getting an error Error: Unexpected request: POST data/employee/1 No more request expected 收到错误Error: Unexpected request: POST data/employee/1 No more request expected

Am using angular-mocks , angular-ui-route in my app.config i've got my $stateProvider routes and my mocks the main one with the issue being the one below: 我在app.config使用angular-mocksangular-ui-route ,我有$stateProvider路由,而我的$stateProvider主要是以下问题:

$httpBackend.whenPOST(/data\/employee\/(\d+)/, {}, {},['id']).respond(function(method, url, data, headers, params){

        console.log('Received these data:', method, url, data, headers, params);

        return [200, {}, {}]
});

Calling via controller: 通过控制器调用:

app.controller("employeeController", ['$scope','$http', "$state", "$stateParams", function($scope, $http, $state, $stateParams){

   $http.post("data/employee/1").then(function(response){


   })
 })

What might be the issue? 可能是什么问题?

为了使模拟$httpBackend.whenPOST(url, [data], [headers], [keys])工作,可选参数dataheader需要在未使用的地方声明为undefined ,而不仅仅是空对象{}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM