Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doc tweak: standalone components usage instructions #1473

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Get the complete changelog here: https://github.com/ngx-translate/core/releases
* [Usage](#usage)
* [Import the TranslateModule](#1-import-the-translatemodule)
* [SharedModule](#sharedmodule)
* [Standalone components](#standalone-components)
* [Lazy loaded modules](#lazy-loaded-modules)
* [Configuration](#configuration)
* [AoT](#aot)
Expand Down Expand Up @@ -101,6 +102,32 @@ you can export the `TranslateModule` to make sure you don't have to import it in
export class SharedModule { }
```

##### Standalone components

For [`Standalone component`](https://angular.io/api/core/Component#standalone) based applications you have to include providers from `TranslateModule` inside your bootstrap configuration options

```ts
bootstrapApplication(AppComponent, {
providers: [
...
importProvidersFrom(HttpClientModule), // or provideHttpClient() in Angular v15+
importProvidersFrom(TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: createTranslateLoader,
deps: [HttpClient]
}
})),
]
})
```

Then you can import `TranslateModule` in your standalone imports:

```ts
@Component({ standalone: true, imports: [ CommonModule, TranslateModule ] })
```

> Note: Never call a `forRoot` static method in the `SharedModule`. You might end up with different instances of the service in your injector tree. But you can use `forChild` if necessary.

##### Lazy loaded modules
Expand Down
Loading