When i switch language on the website, i want to show or hide one tab, if the language is german then show it, if any other language then hide it, my code:
ngOnInit(): void {
this.translate.onLangChange.subscribe({next: (event: { lang: string; }) =>{
if(event.lang && event.lang === 'de'){
this.tabsArray = this.tabsArray.filter((tab) => tab.label !== certainPathLabel );
}
else{
const foundLabel = this.tabsArray.find((tab)=>tab.label == certainPathLabel );
if(!foundLabel) {
this.tabsArray.splice(4,0, {label: certainPathLabel , route: this.routeService.generateUrl(certainPatRoute)})
}
}
this.tabs$.next(this.tabsArray);
}
});
}
This works only if i select german, the tab is hidden but if i then select any other language i cannot display the tab again no matter what i choose, any help?
Do you have the possibility to use a simple observable ?
isGerman$ = this.translate.onLangChange.pipe(
map({ next: (event: { lang: string; }) } => // Are you sure for { } ?
event.lang && event.lang === 'de'
)
);
<tabs>
<tab *ngIf="isGerman$ | async">German</tab>
</tabs>