Save selected colors even by going to another page

0

Any idea how I can have 2 (options) arrays with styles to change the colors in specific places of the site (for example change 3 classes: .header, .footer, .sidebar), but keep the option in which the user clicked even when he went to another page on the site?

    
asked by anonymous 06.05.2016 / 21:54

1 answer

1

An easy way to do this would be to use $ rootScope But beware, it is not advised to save functions / methods here, just data.

You can inject the dependency into your controller where the user chooses the colors:

myApp.controller('colorChangeCtrl', ['$scope' $rootScope, function($scope, $rootScope) {
    $rootScope.colors = {
        header: '#fff',
        sidebar: 'rgb(156,236,148)',
        footer: 'alice-blue'
    };
}]);

and then you can access the $ rootsScope of any controller injected ô and receive the values normally:

myApp.controller('otherCtrl', ['$scope' $rootScope, function($scope, $rootScope) {
    $scope.chosenColors = $rootScope.colors;
}]);

You can also use a service, localstorage, cookies, and even routes, but I find the form faster and require less knowledge to apply. But if you are looking to add knowledge, I suggest you look for these other alternatives.

    
09.05.2016 / 17:51