http-класс перехватчика angularjs (ES6) теряет связь с этим

Я создаю и приложение AngularJS, использующее классы ES6 с трейсером, транслирующимся в ES5 в формате AMD.

в моем модуле я импортирую класс перехватчика и регистрирую его как сервис, а затем регистрирую этот сервис с помощью $ httpProvider.interceptors в module.config:

var commonModule = angular.module(moduleName, [constants.name]);

import authenticationInterceptor from './authentication/authentication.interceptor';

commonModule.service('authenticationInterceptor', authenticationInterceptor);

commonModule.config( $httpProvider =>  {
    $httpProvider.interceptors.push('authenticationInterceptor');
});

Мой класс перехватчика вводит оба$ д и$ окно сервисы, сохраняет их в конструкторе для последующего использования. Я следовал за этой частью с отладчиком, и внедрение происходит правильно:

'use strict';
/*jshint esnext: true */

var authenticationInterceptor = class AuthenticationInterceptor {

    /* ngInject */
    constructor($q, $window) {
        this.$q = $q;
        this.$window = $window;
    }

    responseError(rejection) {
        var authToken = rejection.config.headers.Authorization;
        if (rejection.status === 401 && !authToken) {
            let authentication_url = rejection.data.errors[0].data.authenticationUrl;
            this.$window.location.replace(authentication_url);
            return this.$q.defer(rejection);
        }
        return this.$q.reject(rejections);
    }
}

authenticationInterceptor.$inject = ['$q', '$window'];

export default authenticationInterceptor;

Когда я делаю запрос, который отвечает401 перехватчик срабатывает соответствующим образом, но в методе responseError переменная this указывает на объект окна, а не на мой перехватчик, поэтому у меня нет доступа кэто. $ д или жеэто. $ окно.

Я не могу понять, почему? Есть идеи?

Ответы на вопрос(9)

Ваш ответ на вопрос