When switching the language on the website, I want to display or hide a specific tab. If the language is set to German, then show the tab; if any other language is selected, hide it. Here's 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 logic works for showing and hiding the tab when selecting German. However, there seems to be an issue when trying to display the tab again after selecting a different language. Any suggestions on how to resolve this?