I am editing in the database and there was a typescript error 2339 Here is the code
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Storage } from '@ionic/storage';
import { Platform } from 'ionic-angular';
import { SQLite, SQLiteObject} from '@ionic-native/sqlite';
import { SQLitePorter } from '@ionic-native/sqlite-porter'
import { BehaviorSubject } from 'rxjs/Rx';
import 'rxjs/add/operator/map';
/*
Generated class for the DatabaseProvider provider.
See https://angular.io/guide/dependency-injection for more info on
providers
and Angular DI.
*/
@Injectable()
export class DatabaseProvider {
database: SQLiteObject;
private dbReady: BehaviorSubject<boolean>;
constructor(public http: HttpClient, private sqlitePorter: SQLitePorter, private storage: Storage, private sqlite: SQLite, private platform: Platform)
{
this.dbReady = new BehaviorSubject(false);
this.platform.ready().then(() => {
this.sqlite.create({
name: 'assessment.db',
location: 'default'
})
.then((db:SQLiteObject) => {
this.database = db;
this.storage.get('database_filled').then(val => {
if(val){
this.dbReady.next(true);
}
else{
this.fillDatabase();
}
})
});
});
}
fillDatabase(){
this.http.get('assets/test.sql')
.map (res => res.text())
.subscribe(sql => {
this.sqlitePorter.importSqlToDb(this.database, sql)
.then(data => {
this.dbReady.next(true);
this.storage.set('database_filled', true);
})
});
}
getDatabaseState(){
return this.dbReady.asObservable();
}
}
.map (res => res.text()) this part returns an error. I have tried to alter this and made it .map ((res: Response) => res.text()) then another error would prompt and that is in the line this.sqlitePorter.importSqlToDb(this.database, sql) the error is " Argument of type Promise is not assignable to parameter of type .