2016-07-15 10 views
0

Ich habe ein ES6-Projekt. Ich möchte die Datei in ES5 übertragen. Ich habe eine Schluckaufgabe erstellt. Hier ist das meine Aufgabe mit babel:Warum kann ich meine js-Datei nicht übertragen?

gulp.task('transpile' , function() { 
    console.log('Transpile js '); 
    return gulp.src(['app/**/*.js']) 
    .pipe(babel({ 
     presets: ['es2015'] 
    })) 
    .pipe(ngAnnotate()) 
    .pipe(uglify().on('error', function(e){ 
     console.log(e); 
     })) 
    .pipe(gulp.dest('target/')); 
}); 

Wenn ich meine Aufgabe laufen, ich habe einen Fehler:

events.js:141 
     throw er; // Unhandled 'error' event 
    ^
SyntaxError: /Users/me/myapp/target/tmp/src/content.components/login/login.controller.js: Unexpected token (20:16) 
    18 |  } 
    19 | 
> 20 |  successAuth = (result) => { 
    |    ^
    21 |   this.$rootScope.$broadcast('authenticationSuccess'); 
    22 |   this.$location.path('/'); 
    23 |  }; 
    at Parser.pp.raise (/Users/me/node_modules/babylon/lib/parser/location.js:22:13) 

Das Problem tritt in meinem Controller:

class LoginController { 

    constructor($rootScope, $location, AuthService) { 
     this.AuthService = AuthService; 
     this.$rootScope = $rootScope; 
     this.$location = $location; 
    } 

    login() { 
     this.loading = true; 
     this.AuthService.login({ 
      username: this.username, 
      password: this.password, 
      rememberMe: this.rememberMe 
     }).then(this.successAuth, this.failedAuth); 
    } 

    successAuth = (result) => { 
     this.$rootScope.$broadcast('authenticationSuccess'); 
     this.$location.path('/'); 
    }; 
    failedAuth = (error) => { 
     this.error = 'Identifiant ou mot de passe incorrect'; 
     this.loading = false; 
    }; 
} 

LoginController.$inject = ['$rootScope', '$location', 'AuthService'] 

export default LoginController; 

Wie zu lösen mein Fehler bitte?

+1

Verwenden Sie die 'functionName-() {}' Syntax statt Pfeil Funktionen. – str

Antwort

0

Die Syntax für Klassenmethoden lautet methodName(parameters) { body }.

Schreiben Sie Ihre Klasse wie folgt:

class LoginController { 

    constructor($rootScope, $location, AuthService) { 
     this.AuthService = AuthService; 
     this.$rootScope = $rootScope; 
     this.$location = $location; 
    } 

    login() { 
     this.loading = true; 
     this.AuthService.login({ 
      username: this.username, 
      password: this.password, 
      rememberMe: this.rememberMe 
     }).then(this.successAuth, this.failedAuth); 
    } 

    successAuth(result) { 
     this.$rootScope.$broadcast('authenticationSuccess'); 
     this.$location.path('/'); 
    } 

    failedAuth(error) { 
     this.error = 'Identifiant ou mot de passe incorrect'; 
     this.loading = false; 
    } 

}