我最近决定使用$resource
REST 服务,但很快就遇到了麻烦。我有一个简单的网址:
/r/interface/activate/:active/addr/:address
但是在单元测试中调用它会使其失败:
// expected: POST /r/interface/activate/false/addr/123
// got : POST /r/interface/activate/false/addr/@address
我定义的资源是:
module.factory('NetworkInterfaceActivationService', function ($resource) {
return $resource("/r/interface/activate/:active/addr/:address", {}, {
activate:{method:'POST', params:{active:"true", address:'@address'}, isArray:false},
deactivate:{method:'POST', params:{active:"false", address:'@address'}, isArray:false}
});
});
这就是我如何称呼我的服务!
$scope.deactivateNetworkAddress = function (address) {
NetworkInterfaceActivationService.deactivate({address:address});
};
我错过了什么吗?