0

Our task is to translate language, and that change should reflect in other open tabs/windows of the same website. Integrated ngStorage plugin to access the persisted data via localstorage

$scope.$storage = $localStorage;
        $localStorage.language = langKey; //EN/FR
        $scope.$watch(function () {
            return angular.toJson($localStorage);
        }, function () {
            $scope.language = $localStorage.language;
            $translate.use($localStorage.language); //translate language
});

The above snippet works and language translation is seen in tab and window. But trying to save the language when user clicks on Apply button, does not seem to be working using below code

$scope.close = function (response, selectedlanguage) {

        //user clicks on apply button and window to change language is closed
        if (angular.equals(response, 'Yes')) {

            $window.opener.angular.element('#langchange').scope().changeLanguage(selectedlanguage);
            $window.opener.angular.element(".logo-lg").trigger("click");
            $localStorage.language = selectedlanguage;
            $scope.language = $localStorage.language;
            $window.close('cancel');

        }
};

Though using $cookieStore.put('lang', selectedlanguage); and $cookieStore.get('lang');, I am able to save language in cookie and fetch it as well on next reload.

How do I achieve the same using ngStorage plugin localstorage ?

Slimshadddyyy
  • 4,085
  • 5
  • 59
  • 121
  • maybe is it related to what's said in this answer? (a digest cycle has to occur for your values to be actually stored): https://stackoverflow.com/a/41050184/7393478 – Kaddath Aug 22 '17 at 12:35

1 Answers1

0
var App = angular.module("App", ["angular-storage"]]); 


App.controller('LoginCtrl',function ($scope,store){
 data = {text: Test};
 store.set('token', data);
 console.log('Cookie',store.get('token'))
});
Javier Flores
  • 597
  • 4
  • 7