question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"onLangChange" subscriber in pipe does not fire

See original GitHub issue

I’m submitting a …

[x] bug report

Current behavior It seems that the the onLangChange callback inside the translate pipe is not being called. If I register the callback in my application it is being called, but inside the pipe nothing happens.

Expected/desired behavior The onLangChange subscriber inside the pipe should fire

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
SamVerschuerencommented, Nov 2, 2016

This is a flaw in the documentation and should be updated ASAP. You should never ever call the forRoot() of any module in the SharedModule, or feature module for that matter. There is a reason it is called forRoot, because it should only be called once in the root module, most of the time AppModule.

So move that piece of code, TranslateModule.forRoot to your AppModule and change your SharedModule to this

@NgModule({
    imports: [
        CommonModule,
        HttpModule,
        FormsModule
    ],
    declarations: [
        WelcomePageComponent,  // <--- uses the translate pipe
    ],
    exports: [
        HttpModule,
        WelcomePageComponent,
        CommonModule,
        FormsModule,
        TranslateModule
    ]
})
export class SharedModule {
    static forRoot(): ModuleWithProviders {
        return {
            ngModule: SharedModule,
            providers: [LocaleService /* <--- uses the translateService */],
        };
    }
}
0reactions
gitnikcommented, Nov 2, 2016

Thanks a lot!

Read more comments on GitHub >

github_iconTop Results From Across the Web

translateService.onLangChange.subscribe does not trigger ...
I basically want it to be listening to getLocaleDateFormat and change the value when it changes. UPDATE: I just realized that the problem...
Read more >
ngx-translate Documentation - CodeAndWeb
Returns a stream of translated values of a key (or an array of keys) or the key if the value was not found....
Read more >
How to translate your Angular app with ngx-translate
1. Add ngx-translate to your Angular application 2. Set up the TranslateService in your app.module.ts 3. Create your main language translation file (in...
Read more >
Why You Should Not Put Any Logic in the RxJS Subscribe ...
What is the subscribe callback in Angular? Imperative vs Reactive; Reason #1: you are not using RxJS operators as much as you could ......
Read more >
Angular I18n: How to Internationalize with ngx-translate | Phrase
You can either use a service, directive, or pipe to handle the ... Should this not be the case, please refer to the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found