I'm fairly new to angular and Im wondering how to achieve the following:
Im using a ternary condition in my variables to switch between two languages without refreshing my page and display items (ng-repeat) with the correct titles.
{{isEnglish ? item.name_en : item.name_fr}}
I have a toggle switching isEnglish to true or false, but the the variables don't update themselves when switching the boolean. Do I need to apply the changes? is there a way to do so?
language toggle
<a href="" class="fb border_link" ng-click="changelanguage();">
{{displayLanguage}}
</a>
ng-click function
$scope.changelanguage = function(){
console.log("changing language");
console.log($scope.$parent.isEnglish);
if($scope.selectedLanguage === 'en'){
$translate.use('fr');
$scope.$parent.isEnglish = false;
console.log($scope.$parent.isEnglish);
$scope.selectedLanguage = 'fr';
$scope.displayLanguage = 'English';
console.log("en");
}
else{
$translate.use('en');
$scope.$parent.isEnglish = true;
console.log($scope.$parent.isEnglish);
$scope.selectedLanguage = 'en';
$scope.displayLanguage = 'Français';
console.log("fr");
}
}