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)
Written by Jonathan 'J5' Cook
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Error
Authors
Related Tags
#error
#angularjs
#$http
#typeerror
#transformresponse
#transformrequest
#$resource
#ignoreauthmodule
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#