Add local storage
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
import { Storage } from '@ionic/storage-angular';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class StorageService {
|
||||
private _storage: Storage | null = null;
|
||||
|
||||
constructor(private storage: Storage) {}
|
||||
|
||||
async init() {
|
||||
// If using, define drivers here: await this.storage.defineDriver(/*...*/);
|
||||
const storage = await this.storage.create();
|
||||
this._storage = storage;
|
||||
}
|
||||
|
||||
// Create and expose methods that users of this service can
|
||||
// call, for example:
|
||||
public set(key: string, value: any) {
|
||||
this._storage?.set(key, value);
|
||||
}
|
||||
|
||||
public async getCurrentUserId() {
|
||||
return await this._storage?.get('user-id');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user