标签: gulp-traceur

angularjs http拦截器类(ES6)失去对'this'的绑定

我正在使用ES6类构建AngularJS应用程序,并将跟踪器转换为AMD格式的ES5.

在我的模块中,我导入拦截器类并将其注册为服务,然后使用module.config中的$ httpProvider.interceptors注册此服务:

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

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

commonModule.service('authenticationInterceptor', authenticationInterceptor);

commonModule.config( $httpProvider =>  {
    $httpProvider.interceptors.push('authenticationInterceptor');
});
Run Code Online (Sandbox Code Playgroud)

我的拦截器类注入$ q$ window服务,将它们保存在构造函数中供以后使用.我使用调试器跟踪了这一部分并正确地进行了注入:

'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', …
Run Code Online (Sandbox Code Playgroud)

interceptor angularjs ecmascript-6 traceur gulp-traceur

16
推荐指数
2
解决办法
5410
查看次数

ReferenceError:$ traceurRuntime未定义(在angularjs app中)

我正在使用[gulp-traceur] [1]在我的angularjs应用程序(1.x)中将es6编译为js.当我尝试编译for循环时,我收到错误:

ReferenceError: $traceurRuntime is not defined
Run Code Online (Sandbox Code Playgroud)

看起来我需要将$ traceurRuntime注入我的控制器或其他东西.谁能帮我吗?

javascript angularjs ecmascript-6 gulp gulp-traceur

1
推荐指数
1
解决办法
2576
查看次数