I am working with a select component as shown below:
<label>
{{ "HOME.SELECT" | translate }}
<select #langSelect (change)="translate.use(langSelect.value)" (change)='onOptionsSelected($event)'>
<option *ngFor="let lang of translate.getLangs()" [value]="lang" [selected]="??">
{{ lang }}</option>
</select>
</label>
Within the constructor, the selected language is stored in localstorage like this:
constructor(public translate: TranslateService) {
translate.addLangs(["en-US", "fr-FR", "de-DE"]);
if (localStorage.getItem('language')) {
translate.setDefaultLang(localStorage.getItem('language'));
translate.use(localStorage.getItem('language'));
} else {
translate.setDefaultLang('en');
translate.use('en');
localStorage.setItem("language", "en");
}
}
I'm looking for a way to automatically set the selected index in the dropdown based on the value stored in localstorage. Can anyone help with this?