1

i have this multiple checkbox.

<div ng-repeat="setting in settings">
    <input type="checkbox" name="setting.name" ng-model="setting.value">{{setting.name}}

and in the controller

$scope.settings = [{
           name: 'OrderNr',
           value: ''
       }, {
           name: 'CustomerNr',
           value: ''
       }, {
           name: 'CatalogName',
           value: ''
       }, {
           name: 'OrderDate',
           value: ''
       }, {
           name: 'OrderState',
           value: ''
       }];

when i click the save button, i call this function for store data in local storage

$scope.saveSetting = function() {
    var json = angular.toJson($scope.settings);
    localStorageService.add('settings',json);

};

how can i keep my settings when i reload the page?

3 Answers 3

2

What about using $cookies.

Have a look at angularjs docs

Basically all you need to do is inject the service in the controller as a dependency and use it as an object.

In your controller:

$scope.saveSetting = function() {
    $cookies.settings = $scope.settings;
};

And to use them:

$scope.loadSetting = function() {
     $scope.settings = $cookies.settings;
};

Please let me know if it works for you.

Sign up to request clarification or add additional context in comments.

Comments

0

I would use ngStorage directive. I use it in my app. You would simply set the settings to your storage using ngStorage and then also set the initial value for your settings via ngStorage when the controller loads.

https://github.com/gsklee/ngStorage

Comments

0

You just need to set $scope.settings when your controller loads.

var myCtrl = function($scope) {
    if(localStorage.settings) {
        $scope.settings = angular.fromJson(localStorage.settings);
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.