是否有办法告诉 angularjs($http 服务)在执行 HTTP POST 时不要将某些属性发送到 Json 对象中?
假设我有一个像这样的对象定义:
$scope.toBeSaved = { id : 1,
name: myname,
someAttributeTobeFiltered : 1233459,
}
是否有办法过滤 someAttributeTobeFiltered
在 $http.post(url,$scope.toBeSaved)
调用期间不发送?
提前致谢
最佳答案
这将删除通过 $http 发出的每个请求上的给定属性。
.config(['$httpProvider', function($httpProvider )
{
$httpProvider.defaults.transformRequest = [function(data)
{
if(typeof data === "object")
{
var toSend = angular.copy(data);
delete toSend.someAttributeTobeFiltered;
return toSend;
}
else{
return data;
}
}];
}]);
关于javascript - Angular js : fitlering json properties to be send in a request,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30242266/