javascript - Usage of ngStorage(angularjs) for language option -
i have html
<button class="btn btn-info" ng-click="setlanguage('en')">english</button> <button class="btn btn-info" ng-click="setlanguage('de')">danish</button> <p>{{name[language]}}</p>
and javascript
$scope.language='en'; //initial default value $scope.setlanguage = function(language) { $scope.language = language; }
i binding language button 2 languages.based on language selected, content shown. how store en
or de
localstorage. if refresh or change page also, set language should same. how it. can me here plunker http://plnkr.co/edit/zhmvbwckevkggeberhhe?p=preview
// getter if ($window.localstorage.language) { $scope.language = $window.localstorage.language; } else { $scope.language = 'en'; } // setter $scope.setlanguage = function(language) { $scope.language = language; $window.localstorage.language = language; }
to check resource variables cookies, local storage, etc. under chrome developer tools (access f12) go resources
tab.
Comments
Post a Comment