- Add cordova storage plugin

- Add plugin configuration
- Add storage set and get methods
This commit is contained in:
tiago.kayaya
2020-12-16 16:06:14 +01:00
parent 24c3facbf2
commit 2535921452
7 changed files with 24 additions and 23 deletions
+15 -17
View File
@@ -1,33 +1,31 @@
import { Injectable } from '@angular/core';
/* import { Plugins } from '@capacitor/core';
const { Storage } = Plugins; */
import { Storage } from '@ionic/storage';
@Injectable({
providedIn: 'root'
})
export class StorageService {
constructor() {}
constructor(private storage: Storage) {}
/* // Store the value
async store(storageKey: string, value: any) {
// Store the value
async store(value: any) {
const encryptedValue = btoa(escape(JSON.stringify(value)));
await Storage.set({
key: storageKey,
value: encryptedValue
});
await this.storage.set('user', encryptedValue);;
}
// Get the value
async get(storageKey: string) {
const ret = await Storage.get({ key: storageKey });
return JSON.parse(unescape(atob(ret.value)));
async get(user: any) {
const ret = await this.storage.get('user').then(res=>{
return JSON.parse(unescape(atob(ret.value)));
});
}
async removeStorageItem(storageKey: string) {
await Storage.remove({ key: storageKey });
}
/* async removeStorageItem(storageKey: string) {
await this.storage.remove({ key: storageKey });
} */
// Clear storage
async clear() {
await Storage.clear();
} */
await this.storage.clear();
}
}