The variable in the constructor is not being utilized. Instead, it is used inside a subscription callback that occurs asynchronously either after or during the constructor call. To prevent currentLang
from becoming undefined, you can initialize it.
currentLang = ''
constructor(
private fb: FormBuilder,
private langService: LangService ,
private translate: TranslateService
) {
this.langService.currentLang.subscribe((lang) => {
this.currentLang = lang;
this.showCurrentLang = this.currentLang === 'en';
if (this.AfterDisplayIndustries) {
this.displayIndustries();
}
});
}
displayIndustries (industry?: IIndustry) {
this.AfterDisplayIndustries = true;
return (this.currentLang === 'en' && industry) ? industry.name : industry.nameCZ;
}
(Your code has also been made more concise)