![](/img/trans.png)
[英]AngularJS fake $httpBackend.whenPOST() Uncaught TypeError: Cannot read property '2' of undefined
[英]AngularJs $httpbackend.whenPOST regular expression not working
收到错误Error: Unexpected request: POST data/employee/1 No more request expected
我在app.config
使用angular-mocks
, angular-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, {}, {}]
});
通过控制器调用:
app.controller("employeeController", ['$scope','$http', "$state", "$stateParams", function($scope, $http, $state, $stateParams){
$http.post("data/employee/1").then(function(response){
})
})
可能是什么问题?
为了使模拟$httpBackend.whenPOST(url, [data], [headers], [keys])
工作,可选参数data
和header
需要在未使用的地方声明为undefined
,而不仅仅是空对象{}
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.