Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Issue with interceptors in $resource #11201

@Avcajaraville

Description

@Avcajaraville

Im having a weird behavior manipulating a response through $resource with a custom interceptor.

If I use a response interceptor like this :

angular.module( 'app.services', [] )
  .factory( 'Product', function( $resource, routesConfig ) {
      return $resource( routesConfig.catalogueEndPointg(), {}, { 
        query: { 
          method :'GET', 
          isArray : false, 
          params : { 
            page : '@currentPage'
          },
          interceptor: {
            response: function( response ) {
              // DO STUFF
              return response;
            }
          },
        } 
      });
    });

Then, from my controller :

angular.module( 'app.controllers', [])
  .controller( 'DummyController', function( $scope, Product ){
    productsPromise.$promise
      .then(
        // Success
        function ( response ) {
          console.log( response );
        });
  });

At this point, this is the output of the console.log( response ) :

captura de pantalla 2015-02-26 a la s 17 40 11

On the response object, I have the data object, as expected, but I also have this resource : Resource object which also includes the response data again.

But, if I dont use a interceptor at all; Im getting the expected response :

captura de pantalla 2015-02-26 a la s 17 42 47

I dont understand this behavior and Im concern about perform or memory issues.

Can somebody clarify this ?

PS: I need to use interceptors, because I have to modify the response from server.

Original question on stackoverflow:

http://stackoverflow.com/questions/28748053/angularjs-issue-with-interceptors-in-resource/

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions