angular.module('myApp.services', []) .factory('Base',function($rootScope,cfpLoadingBar){ return{ set: function(key, data) { return window.localStorage.setItem(key, window.JSON.stringify(data)); }, get: function(key) { return window.JSON.parse(window.localStorage.getItem(key)); }, remove: function(key) { return window.localStorage.removeItem(key); } } })
controller中調用時先注入Basejavascript
而後直接用java
Base.set("name","test"); Base.get("name");//test;獲取 Base.remove("name");//刪除