我正在使用 sql storage 2.2,到目前为止我还没有遇到任何问题
将其安装为
ionic cordova plugin add cordova-sqlite-storage
然后
npm install --save @ionic/storage
至于文档Ionic Storage您需要将存储服务添加到您的模块
import { IonicStorageModule } from '@ionic/storage';
@NgModule({
declarations: [
// ...
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp),
IonicStorageModule.forRoot()<---------- THIS
],
bootstrap: [IonicApp],
entryComponents: [
// ...
],
providers: [
// ...
]
})
export class AppModule {}
那么你可以像这样使用它
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import {Observable} from "rxjs/Observable";
import 'rxjs/add/observable/fromPromise';
import { Storage } from '@ionic/storage';
@Injectable()
export class DatabaseProvider {
constructor(public http: HttpClient, private _storage:Storage) {
}
getData(keyName:string):Observable<any> {
return Observable.fromPromise(this._storage.get('keyName'));
}
setData(keyName:string,data:any):Observable<any>{
return Observable.fromPromise(this._storage.set(keyName,JSON.stringify(data)));
}
}
请记住,我只是根据工作解决方案编写的,但未经测试