import { Storage } from '@ionic/storage' ; import { Injectable } from '@angular/core' ; export class @ Injectable ( ) export class PreferencesDAO { private baseCollectionName : string = 'prefs' ; public constructor ( private storage ) { } template T param { string } key returns { Promise < T > } public getKey < T > ( key ) { return this . storage . get ( `${ this . baseCollectionName }.${ key }` ) . then ( value => { let tmp ; try { tmp = < T > JSON . parse ( value ) ; } catch ( e ) { tmp = null ; } finally { return tmp ; } } ) ; } param { string } key param { * } value returns { Promise < void > } public setKey ( key , value ) { return this . storage . set ( `${ this . baseCollectionName }.${ key }` , JSON . stringify ( value ) ) ; } }