forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathangular-local-storage-tests.ts
73 lines (59 loc) · 1.91 KB
/
angular-local-storage-tests.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/// <reference path='../angularjs/angular.d.ts' />
/// <reference path='angular-local-storage.d.ts' />
interface TestScope extends ng.IScope {
submit: (key: string, value: string) => boolean;
getItem: (key: string) => string;
removeItem: (key: string) => boolean;
clearNumbers: () => boolean;
clearAll: () => boolean;
unbind: Function;
update: (val: string) => void;
property: string;
}
export class TestController {
constructor($scope: TestScope, localStorageService: ng.local.storage.ILocalStorageService) {
// isSupported
if (localStorageService.isSupported) {
// do something
}
// getStorageType
var storageType: string = localStorageService.getStorageType();
// set
$scope.submit = (key, value) => {
return localStorageService.set(key, value);
};
// get
$scope.getItem = (key) => {
return localStorageService.get<string>(key);
};
// remove
$scope.removeItem = (key) => {
return localStorageService.remove(key);
};
// clearAll(regexp)
$scope.clearNumbers = () => {
return localStorageService.clearAll(/^\d+$/);
};
// clearAll
$scope.clearAll = () => {
return localStorageService.clearAll();
};
// keys
var lsKeys = localStorageService.keys();
// bind
localStorageService.set('property', 'oldValue');
$scope.unbind = localStorageService.bind($scope, 'property');
// deriveKey
console.log(localStorageService.deriveKey('property')); // ls.property
// length
var lsLength: number = localStorageService.length();
}
}
var app = angular.module('angular-local-storage-tests', ['LocalStorageModule']);
app.config(function (localStorageServiceProvider: ng.local.storage.ILocalStorageServiceProvider) {
localStorageServiceProvider
.setPrefix('myApp')
.setStorageType('sessionStorage')
.setNotify(true, true);
});
app.controller('TestController', TestController);