javascript - How to set rtl property based on language change in angularjs? -
hi developing angularjs application , multilingual application english , arabic. whenever select arabic language want apply rtl support html tag. work fine want based on language selection.
below html code
<div class="language"> <a href="#" ng-click="changelanguage(lang == 'de_ar' ? 'de_en' : 'de_ar')"> <img ng-src="images/{{ lang == 'de_ar' ? 'english.png' : 'arabic.png' }}" /> </a> </div>
below angular code
$scope.changelanguage = function (lang) { $scope.lang = lang == 'de_ar' ? 'de_ar' : 'de_en'; $cookiestore.put("preferredlanguage", $scope.lang); $translate.use($scope.lang); }
in above code if language selected want add otherwise . tried below.
if($scope.lang="de_ar") { $scope.rtl="rtl" }
below html tag.
<html ng-app="roslpapp" dir="{{rtl}}">
above code doesnt provide rtl support. may fix this? may know missing here? appreciated. thank you.
you can ternary operations on $scope.lang
decide whether page should ltr or rtl
<html ng-app="roslpapp" ng-controller="roslpappcontroller" dir="{{lang=='de_ar'?'rtl':'ltr'}}">
you have define ternary conditions within scope of controller trigger. place ng-controller
on html tag or move dir place defining ng-controller
Comments
Post a Comment