Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

I am trying to implement ng2-translate pipe on my Angular2/Ionic2 app which is totally written on JavaScript ES6.

However, I am stuck on a step in the setup phase in which I need to write a piece of code in JavaScript ES6. What I found so far on their documentation and over the internet is written on TypeScript which throws an Syntax error while trying to implement it on my app.

The code:

      @Component({
          template: '<ion-nav swipeBackEnabled="true" [root]="rootPage"></ion-nav>',
        config: {}, 
        providers: [
         {
         //The Syntax error throws on this line, which is needed to be re-written on JS
           provide: TranslateLoader,
           useFactory: (http: Http) => new TranslateStaticLoader(http, 'assets/i18n', '.json'),
           deps: [Http]
         },
         TranslateService
       ],
       pipes: [TranslatePipe]
      })

What I need to know is that how to convert that piece of code written on TypeScript to JavaScript ES6 in order to make it run.

share|improve this question
up vote 1 down vote accepted

Without knowing what the error is... Perhaps it is sufficient to remove the type from your function definition for the attribute useFactory.

  @Component({
      template: '<ion-nav swipeBackEnabled="true" [root]="rootPage"></ion-nav>',
    config: {}, 
    providers: [
     {
       provide: TranslateLoader,
       useFactory: (http) => new TranslateStaticLoader(http, 'assets/i18n', '.json'),
       deps: [Http]
     },
     TranslateService
   ],
   pipes: [TranslatePipe]
  })
share|improve this answer
    
Thanks a lot! It worked! – Hamza L. Aug 12 at 21:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.