标签:style blog color io os ar for sp div
1 angular.module(‘locals‘,[]) 2 .factory(‘ls‘, [‘$window‘, function($window) { 3 return { 4 set: function(key, value) { 5 $window.localStorage[key] = value; 6 }, 7 get: function(key, defaultValue) { 8 return $window.localStorage[key] || defaultValue; 9 }, 10 setObject: function(key, value) { 11 $window.localStorage[key] = JSON.stringify(value); 12 }, 13 getObject: function(key) { 14 return JSON.parse($window.localStorage[key] || ‘{}‘); 15 } 16 } 17 }]);
把本地存儲定義成一個數據模型,方便下次的調用;
新建了一個 locals 模板
locals 創建了一個服務 ls
調用的時候 聲明locals模板 和注入 ls 服務
1 angular.module(‘starter‘, [‘ionic‘,‘locals‘]) 2 3 .run(function($ionicPlatform,ls) { 4 $ionicPlatform.ready(function() { 5 6 ls.set(‘name‘, ‘test‘); 7 console.log(ls.get(‘name‘)); 8 ls.setObject(‘info‘, { 9 name: ‘Thoughts‘, 10 text: ‘Today was a good day‘ 11 }); 12 13 var infos = ls.getObject(‘info‘); 14 console.log(infos); 15 16 // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard 17 // for form inputs) 18 if(window.cordova && window.cordova.plugins.Keyboard) { 19 cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); 20 } 21 if(window.StatusBar) { 22 StatusBar.styleDefault(); 23 } 24 }); 25 });
标签:style blog color io os ar for sp div
原文地址:http://www.cnblogs.com/xieyier/p/4021696.html