title: AngularJS $resource interceptors
body: <p>How do I add interceptors to a <code>$resource</code> call?</p>
  
  <p>Let's say I have a resource factory called <code>Users</code>, like so;</p>
  
  <pre><code>app.factory('Users', ['$resource', 'resourceInterceptor',
    function ($resource, resourceInterceptor) {
      return $resource(
        'users/:user_id',
        {
          user_id: '@id'
        },
        {
          query: {
            method: 'GET', // Not changing the default method, just adding an interceptor
            interceptor: resourceInterceptor // Is there any better way to do this.. like globally?
          },
          save: {
            method: 'POST', // Same here
            interceptor: resourceInterceptor // Again...
          },
          ..., // And so on
        }
      );
    }]);
  </code></pre>
  
  <p>and my <code>resourceInterceptor</code> service looks like;</p>
  
  <pre><code>app.factory('resourceInterceptor', ['$rootScope',
    function ($rootScope) {
      return {
        request: function () {
          // This function isn't executed at all?
          $rootScope.loading = true;
        },
        response: function () {
          $rootScope.loading = false;
        },
        responseError: function () {
          $rootScope.loading = false;
        }
      };
    }]);
  </code></pre>
  
  <p>First of all, the <code>request</code> intercept function is never executed, why not?</p>
  
  <p>Secondly, having to hardcode the interceptor to existing <code>$resource</code> methods is very tedious , is there a way to easier assign interceptors to specific <code>$resource</code> calls, or maybe even assign an interceptor to all <code>$resource</code> calls?</p>