Last Updated: February 25, 2016
·
3.692K
· 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)

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

AngularJS pages are long-lived browser apps with the same script risk as a newer single-page app. Third-party code in the template can read forms and values rendered on the page.

Security insights from Cside