转换在 angularjs http
服务中做了什么。以下是文档中如何解释自定义转换的示例。
Both requests and responses can be transformed using transformation functions: transformRequest and transformResponse. These properties can be a single function that returns the transformed value (function(data, headersGetter, status)) or an array of such transformation functions, which allows you to push or unshift a new transformation function into the transformation chain
function appendTransform(defaults, transform) {
// We can't guarantee that the default transformation is an array
defaults = angular.isArray(defaults) ? defaults : [defaults];
// Append the new transformation to the defaults
return defaults.concat(transform);
}
$http({
url: '...',
method: 'GET',
transformResponse: appendTransform($http.defaults.transformResponse, function(value) {
return doTransform(value);
})
});
什么变换会做?我无法从文档中得到解释,可以解释一下吗?
感谢您的帮助。
最佳答案
检查一下。这应该让您了解如何使用以及为什么它作为 $http 的服务之一存在
transforming your response using services.transformer.ApiResponse
因此您可以重新制定函数的 JSON.parse(data) 以获得您想要的响应!
关于angularjs - 在 AngularJS 中转换请求和响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32563914/