您的位置:首页 > Web前端 > AngularJS

Angular Local Storage 使用方法

2016-08-10 11:44 253 查看
JS Example
var YourCtrl = function($scope, localStorageService, ...) {
// To add to local storage
localStorageService.set('localStorageKey','Add this!');
// Read that value back
var value = localStorageService.get('localStorageKey');
// To remove a local storage
localStorageService.remove('localStorageKey');
// Removes all local storage
localStorageService.clearAll();
// You can also play with cookies the same way
localStorageService.cookie.set('localStorageKey','I am a cookie value now');
}

API Access

CallArgumentsActionReturns
isSupported
n/aChecks the browsers support for local storageBoolean for success
set
key, valueAdds a key-value pair to the browser local storageBoolean for success
get
keyGets a value from local storageStored value
remove
key, ...Removes a key-value pairs from the browser local storagen/a
clearAll
n/aWarning Removes all local storage key-value pairs for this app. It will optionally take a string, which is converted to a regular expression, and then clears keys based on that regular expression.Boolean for success
cookie
set | get | remove | clearAllEach function within cookie uses the same arguments as the coresponding local storage functionsn/a
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐