I am building and AngularJS app using ES6 classes with traceur transpiling to ES5 in AMD format.
in my module I import the interceptor class and register it as a service
To add to the conversation, you could return an object from the constructor that contains explicitly bound class methods.
export default class HttpInterceptor {
constructor($q, $injector) {
this.$q = $q;
this.$injector = $injector;
return {
request: this.request.bind(this),
requestError: this.requestError.bind(this),
response: this.response.bind(this),
responseError: this.responseError.bind(this)
}
}
request(req) {
this.otherMethod();
// ...
}
requestError(err) {
// ...
}
response(res) {
// ...
}
responseError(err) {
// ...
}
otherMethod() {
// ...
}
}