我正在使用客户端的javascript angularJS库和spring框架(java)开发应用程序以进行后端实现。 对于其中一个服务,我在Response Header中返回一个参数。问题是我在服务电话后无法获得此值。
这是工厂:
angular.module('app')
.factory('financeDocumentService', ['$resource', 'SERVER_FOR_SERVICES',
function ($resource, SERVER_FOR_SERVICES) {
var url = SERVER_FOR_SERVICES + '/sapi/finance/document';
return $resource(url + '/:id', {id: '@id'}, {
'get': {method: 'GET'},
'isReferencedDocumentIdCompensated':
{
method: 'GET',
isArray: false,
url: url + '/is_compensated?referenced_document_id=:id',
params: {id: '@id'},
headers: {'Access-Control-Expose-Headers': 'IsCompensated'},
transformResponse: function (data, headers) {
response = {};
response.data = data;
response.headers = headers();
console.log(headers());
return response;
}
}
});
}]);
这是控制器上的代码:
$scope.flightRecords[i].financeDocument =
financeDocumentService
.isReferencedDocumentIdCompensated(
{id: $scope.flightRecords[i].id}).$promise.then(
function(data) {
console.log(data.headers);
}
);
结果如下:
对象{cache-control:“no-cache,no-store,max-age = 0,must ...”,pragma:“no-cache”,expires:“0”} < / p>
这是标题列表值:
Access-Control-Allow-Origin: http://localhost:8383
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Content-Length: 0
Date: Thu, 29 Jun 2017 18:19:23 GMT
Expires: 0
Pragma: no-cache
Vary: Origin
X-Application-Context: application:local
X-Frame-Options: DENY
X-XSS-Protection: 1; mode=block
access-control-allow-credentials: true
isCompensated: false
x-content-type-options: nosniff
非常感谢!