Answer the question
In order to leave comments, you need to log in
How to add a class to a tag?
There is a template, when you click on languages, a class is added to them, but when you first load the page, you also need to add it to highlight the current language
<div ng-init="selectedLang = { currentLanguage } " class="buttonsPanelRow">
<p id="ru" ng-class="{'setLanguageButtonActive':selectedLang === 'ru'}" class="setLanguageButton" ng-click='switchLanguage("ru"); selectedLang = "ru"'>Русский</p>
<p id="en" ng-class="{'setLanguageButtonActive':selectedLang === 'en'}" class="setLanguageButton" ng-click='switchLanguage("en"); selectedLang = "en"'>English</p>
</div>
$scope.switchLanguage = function(key) {
$translate.use(key);
localStorage.setItem('NG_TRANSLATE_LANG_KEY', key);
}
Answer the question
In order to leave comments, you need to log in
onInit
You need to check the existence of the desired variable in
the life cycle hook localStorage
and, if such a variable exists, initialize it with selectedLang
the desired value.
If the variable localStorage
does not exist, it should be initialized selectedLang
with a standard value, for example en
.
https://angular.io/guide/lifecycle-hooks
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question