Add ngStorage

This commit is contained in:
Jakub Pistek
2016-02-19 16:12:27 +01:00
parent 95b7178e0e
commit f59279e1f7
2 changed files with 70 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
/// <reference path="../angularjs/angular.d.ts" />
/// <reference path="ngstorage.d.ts" />
var app: any;
app.controller('MainCtrl', function ($localStorage: angular.storage.ILocalStorageService) {
$localStorage.set('MyKey', 'value');
$localStorage.get('MyKey');
$localStorage.$default({
counter: 1
});
$localStorage.$reset({
counter: 1
});
$localStorage.$apply();
});
app.config(['$localStorageProvider',
function ($localStorageProvider: angular.storage.ILocalStorageProvider) {
$localStorageProvider.setKeyPrefix('NewPrefix');
$localStorageProvider.get('MyKey');
$localStorageProvider.set('MyKey', { counter: 'value' });
var mySerializer = function (value:any):string {
return value.toString();
};
var myDeserializer = function (value:string):any {
return value;
};
$localStorageProvider.setSerializer(mySerializer);
$localStorageProvider.setDeserializer(myDeserializer);
}
]);

28
ngstorage/ngstorage.d.ts vendored Normal file
View File

@@ -0,0 +1,28 @@
// Type definitions for ngstorage 0.3.10
// Project: https://github.com/gsklee/ngStorage
// Definitions by: Jakub Pistek <https://github.com/kubiq>
// Definitions: https://github.com/kubiq/DefinitelyTyped
/// <reference path='../angularjs/angular.d.ts' />
declare module angular.storage {
export interface ILocalStorageService {
$default(items: any):ILocalStorageService;
$reset(items: any):ILocalStorageService;
$apply():void;
get<T>(key: string): T;
set<T>(key: string, value: T): T;
}
export interface ILocalStorageProvider extends angular.IServiceProvider {
get<T>(key:string): T;
set<T>(key:string, value:T): T;
setKeyPrefix(prefix: string):void;
setSerializer(serializer: (value: any)=>string):void;
setDeserializer(deserializer: (value: string)=>any):void;
}
}