demo-app.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. 'use strict';
  2. window.angular.module('demoModule', ['LocalStorageModule'])
  3. .config(function(localStorageServiceProvider){
  4. localStorageServiceProvider.setPrefix('demoPrefix');
  5. // localStorageServiceProvider.setStorageCookieDomain('example.com');
  6. // localStorageServiceProvider.setStorageType('sessionStorage');
  7. })
  8. .controller('DemoCtrl',
  9. function($scope, localStorageService) {
  10. $scope.localStorageDemo = localStorageService.get('localStorageDemo');
  11. $scope.$watch('localStorageDemo', function(value){
  12. localStorageService.set('localStorageDemo',value);
  13. $scope.localStorageDemoValue = localStorageService.get('localStorageDemo');
  14. });
  15. $scope.storageType = 'Local storage';
  16. if (localStorageService.getStorageType().indexOf('session') >= 0) {
  17. $scope.storageType = 'Session storage';
  18. }
  19. if (!localStorageService.isSupported) {
  20. $scope.storageType = 'Cookie';
  21. }
  22. $scope.$watch(function(){
  23. return localStorageService.get('localStorageDemo');
  24. }, function(value){
  25. $scope.localStorageDemo = value;
  26. });
  27. $scope.clearAll = localStorageService.clearAll;
  28. }
  29. );