ngx-translate / core

The internationalization (i18n) library for Angular
MIT License
4.53k stars 578 forks source link

Doc tweak: standalone components usage instructions #1473

Closed 0xfraso closed 3 weeks ago

0xfraso commented 9 months ago

Hi there,

just opened this PR to help people find instructions about using ngx-translate in standalone based applications

hope you find this useful

markodjunev commented 5 months ago

I did exactly the same thing. However I got the following error TypeError: this.handler.handle is not a function on translate.use(). This is my code:

@Component({ selector: 'app-header', standalone: true, imports: [CommonModule, TranslateModule], templateUrl: './header.component.html', styleUrl: './header.component.css' }) export class HeaderComponent { private languages: string[] = ['fr', 'en'];

constructor( protected translate: TranslateService ) { translate.addLangs(this.languages);

translate.use('en')

}

0xfraso commented 5 months ago

Hi @markodjunev, by default ngx-translate uses HttpClient as dependency, so make sure to put provideHttpClient() as provider into your bootstrap function.

CodeAndWeb commented 2 months ago

I've included it in the docs... https://ngx-translate.org/getting-started/translation-files/#standalone-components