First, due diligence. Here I see how the change detection works. Here is a blog elaborating and explaining the subject. Here I can read about environments. Here I have examples on the change detection on component’s parts.
Nowhere I look, I can see how to react to changes in the fields of the injected environment. So I can’t even provide a minimal example.
Is it possible to detect a change in a variable that I import into my component like this?
import { environment } from "src/environments/environment";
The reason is that I’m toggling the language marker in that file and I want to all my pipes for translation to be recalculated. It work in the component that the click happens in but then, I need to distribute said change to all the other parts.
onLingoClick() {
// Lang is an enum containing language codes.
const count = Object.keys(Lang).length / 2;
environment.language = (environment.language + 1) % count;
this.lingo = environment.language;
}
Then, I have the pipe doing the projection of the code to one of the translations.
@Pipe({ name: 'lang' })
export class LanguagePipe implements PipeTransform {
transform(code: string, lang: Lang = environment.language): string { ... }
}
Is it even doable? If not, how can I approach it in a better way? I could register each component and listen to the language changes using an observable. However, it seems like a bit of an overkill.