0
私のionic2アプリケーションでは、ユーザーがアプリケーションを閉じて再オープンしても使用できるようにユーザー情報を保存する必要があります。したがって、私はこれにSqlStorage Serviceを使用しています。コードはかなり長く、醜いですがTypescript(Ionic2)でゲッターとセッターを書く
:
import { Injectable } from '@angular/core';
import {Storage, SqlStorage} from 'ionic-angular';
@Injectable()
export class Profile {
private _storage: any;
constructor(private _api: ApiEndpoint, private _uploadService: UploadService) {
this._storage = new Storage(SqlStorage);
}
get firstname(): string {
return this._storage.get('firstname');
}
set firstname(value: string) {
this._storage.set('firstname', value);
}
get lastname(): string {
return this._storage.get('lastname');
}
set lastname(value: string) {
this._storage.set('lastname', value);
}
get username(): string {
return this._storage.get('username');
}
set username(value: string) {
this._storage.set('username', value);
}
....
....
.... and so on for every field
私の質問があり、このコードを書くための良い方法はありますか?