angular-local-storage
An Angular module that gives you access to the browsers local storage
一个能够让你访问浏览器本地数据存储(localStorage、sessionStorage、cookies)的angular模块
代码库:https://github.com/grevory/angular-local-storage
bootcdn:http://www.bootcdn.cn/angular-local-storage/
官方文档:https://github.com/grevory/angular-local-storage/blob/master/README.md
个人常用:
<script type="text/javascript" src="angular.min.js"></script> <script type="text/javascript" src="angular-local-storage.min.js"></script> <script> //注入 var myApp = angular.module('myApp', ['LocalStorageModule']); //配置 myApp.config(function (localStorageServiceProvider) { localStorageServiceProvider //默认使用“ls.”为键名前缀,以避免命名冲突导致数据遭到污染,更改前缀方法如下: .setPrefix('yourAppName') //默认使用localStorage,若有需要可以换成sessionStorage //.setStorageType('sessionStorage') //默认启用“cookies代替机制”,即:当浏览器不支持localStorage时,将自动使用cookies替代。关闭方法如下: .setDefaultToCookie(false); }); //使用 myApp.controller('MainCtrl', function($scope, localStorageService) { //存储 localStorageService.set(key, val); //获取 localStorageService.get(key); //移除单个 localStorageService.remove(key); //移除多个 localStorageService.remove(key1, key2, key3); //移除所有 localStorageService.clearAll(); }); </script>
有朋自远方来...评论一下呗O(∩_∩)O