lephyrus / ngx-translate-messageformat-compiler

Advanced pluralization (and more) for ngx-translate, using standard ICU syntax which is compiled with the help of messageformat.js.
MIT License
93 stars 29 forks source link

Can't resolve all parameters for TranslateMessageFormatCompiler: (?). #17

Closed alonstar closed 6 years ago

alonstar commented 6 years ago

I updated to last version and get this error

Uncaught Error: Can't resolve all parameters for TranslateMessageFormatCompiler: (?).
at syntaxError (compiler.js:485)
at CompileMetadataResolver._getDependenciesMetadata (compiler.js:15692)
at CompileMetadataResolver._getTypeMetadata (compiler.js:15527)
at CompileMetadataResolver._getInjectableMetadata (compiler.js:15507)
at CompileMetadataResolver.getProviderMetadata (compiler.js:15867)
at eval (compiler.js:15778)
at Array.forEach (<anonymous>)
at CompileMetadataResolver._getProvidersMetadata (compiler.js:15738)
at eval (compiler.js:15210)
at Array.forEach (<anonymous>)

and the app.modules.ts

TranslateModule.forRoot({
  compiler: {
    provide: TranslateCompiler,
    useClass: TranslateMessageFormatCompiler
  }
})

but useFactory: TranslateMessageFormatCompilerFactory it works. If I want to use useClass, What should I do?

lephyrus commented 6 years ago

Yeah, I messed that up, sorry. I'm beginning to think that passing non-injectable arguments to a provider's constructor is problematic. I'll have to investigate. For now you can use the factory function but not pass a config object:

export function TranslateMessageFormatCompilerFactory() {
  return new TranslateMessageFormatCompiler();
}

@NgModule({
  // ...
  imports: [
    // ...
    TranslateModule.forRoot({
      compiler: {
        provide: TranslateCompiler,
        useFactory: TranslateMessageFormatCompilerFactory
      }
    })
  ]
})
lephyrus commented 6 years ago

I've unpublished v2.2.0 for now to prevent more people from running into this.