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.

I want to project the result of my $http call into another model in order to make the projection global to the service call.

In other words, the result i get from my http/api call is not using the exact model i want.

How do i do this projection within my service class?

angular.module('openart')
.factory('BritishLibraryApi', ['$http', function ($http) {
    return {
        getPage:function(page){
            return $http({method:"GET",url:'/api/british-library/'+page})
                .success(function(data){
                    //would like to do something here like
                    return data.results.map(function(i){

                        //project i into another model here
                        return {

                        };
                    });
                });
        }
    };
}]);
share|improve this question
    
You could put in your service an other service with a setter/getter and getByPageId –  Whisher Dec 19 '13 at 15:07
    
How do you plan to bind to the $scope in the controller? Do you want to return a promise here? –  Davin Tryon Dec 19 '13 at 15:30

1 Answer 1

If you create your own promise and resolve to your mapped data

angular.module('openart')
.factory('BritishLibraryApi', ['$http','$q', function ($http,$q) {
    return {
        getPage:function(page){
            var defer=$q.defer();
            $http({method:"GET",url:'/api/british-library/'+page})
                .success(function(data){
                    //would like to do something here like
                    defer.resolve(data.results.map(function(i){

                        //project i into another model here
                        return {
                        };
                    }));
                });
            return defer.promise;
        }
    };
}]);
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.