【发布时间】:2018-08-08 02:29:25
【问题描述】:
我正在数据库中进行编辑,出现打字稿错误 2339 这是代码
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()) 这部分返回错误。我试图改变它并使它成为 .map ((res: Response) => res.text()) 然后会提示另一个错误,那就是 this.sqlitePorter.importSqlToDb(this.database, sql) 错误is " Promise 类型的参数不能分配给 类型的参数。
【问题讨论】:
标签: angular typescript