angularjs http interceptor class (ES6) loses binding to 'this'

后端 未结 9 1628
轮回少年
轮回少年 2021-02-05 11:14

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

9条回答
  •  执笔经年
    2021-02-05 11:50

    export default class AuthInterceptor{
    
    
        /*@ngInject;*/
        constructor(SomeService,$q){
    
            this.$q=$q;
            this.someSrv = SomeService;
    
    
    
            this.request = (config) =>{
                ...
                this.someSrv.doit();
                return config;
    
            }
    
            this.response = (response)=>{
                ...
                this.someSrv.doit();
                return response;
            }
    
            this.responseError = (response) => {
               ...
               return this.$q.reject(response);
            }
    
    
    
        }
    
    
    
    }
    

提交回复
热议问题