Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

This simple problem is bugging me. I have a custom value in my response header from the Web Api Rest server. I can see it it Firebug as: X-TotalPages 204 I try to get it in my AngularJS controller. Code below. But I cant find any good examples how to do this. console.log(headers()['X-TotalPages']); logs 'undefined'


    var assets = angular.module("Assets", ['ui.bootstrap']);
    assets.controller('AssetSearchController', function ($scope, $http) {
        $scope.test = 'very';
        $scope.getItems = function () {
            $http({ method: 'GET', url: 'http://localhost:57772/api/assets', params: { search: 1, page: 0, pageSize: 10 } }
                ).success(function (data, status, headers, config) {
                    $scope.currentPage = 4;                
                    console.log(headers()['X-TotalPages']);

                $scope.items = data;
            }).
            error(function (data, status) {
                console.log(JSON.stringify(data));
                console.log(JSON.stringify(status));
            });

        };

share|improve this question
2  
What's the output of console.log(headers()); ? –  mafis Feb 27 '14 at 9:37
2  
Please see stackoverflow.com/questions/17038436/… –  BKM Feb 27 '14 at 9:44
    
Thanks for the quick reply. console.log(headers()); returns Headers: [object Object] so its there. I have already looked at the other issue and it does not help. This is my response, it seems to be returned by the rest server :[IMG]i58.tinypic.com/5lrzft.png[/IMG] –  Jensiator Feb 27 '14 at 9:54
1  
And my web-config in Rest service:<httpProtocol> <customHeaders> <add name ="Access-Control-Expose-Headers" value="X-TotalPages"/> <add name="Access-Control-Allow-Origin" value="" /> <add name="Access-Control-Allow-Methods" value="POST,GET,DELETE,PATCH,PUT,OPTIONS" /> <add name="Access-Control-Allow-Headers" value="" /> </customHeaders> </httpProtocol> –  Jensiator Feb 27 '14 at 9:57
1  
Shouldn't it be headers('X-TotalPages')? –  Wawy Feb 27 '14 at 10:03

1 Answer 1

You should use: headers('X-TotalPages')

(Posting Wawy's answer so the question can be resolved.)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.