Last Updated: February 25, 2016
·
3.258K
· j5

AngularJS TypeError: Cannot read property 'ignoreAuthModule' of undefined

Getting the error:

TypeError: Cannot read property 'ignoreAuthModule' of undefined

in your AngularJS app?

ignoreAuthModule is part of the 3rd party angular-http-auth module, where an interceptor is used to buffer requests and allow a visitor to log in to your app after requests requiring privileges are made.

In my case, for some requestss, I was adding to / replacing the default request or response transformers something like this:

var transReqDefaults = $http.defaults.transformRequest,
  transRespDefaults = $http.defaults.transformResponse;

transReqDefaults = angular.isArray(transReqDefaults) ? transReqDefaults : [ transReqDefaults ];
transRespDefaults = angular.isArray(transRespDefaults) ? transRespDefaults : [ transRespDefaults ];

return $resource(resoureURL,
  {},
  {
    newMethod: {
       method: 'GET',
       isArray: false,
       transformResponse: transRespDefaults.concat(
         (function transformNewMethodResponse (data, headers) { ... })
       )     
     }
   }
);

When the transformer is called, this was undefined, which resulted in the TypeError. To solve the problem, the new transform function must be bound to $http.

(function transformNewMethodResponse (data, headers) {
...
}).bind($http)