1

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.

Hamza L.
  • 1,783
  • 4
  • 25
  • 47

1 Answers1

1

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]
  })
Lucas Tétreault
  • 953
  • 5
  • 15