IONIC 4 + Angular7: ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'then' of undefined
IONIC 4 + Angular7: ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'then' of undefined
我想将创建 SQLite 数据库的结果分配给 SQLiteObject 类型的变量数据库,因此我必须在 "then" 块中执行此操作,但它显示
error ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'then' of undefined.
关于这个错误的大部分文章我都试过了"ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'then' of undefined"
但是 none 个是我的答案
constructor(public http: Http,
private sqlitePorter: SQLitePorter,
private storage: Storage,
private sqlite: SQLite,
private plateform: Platform) {
this.databaseReady = new BehaviorSubject(false);
this.plateform.ready().then(() => {
this.sqlite.create({
name: 'developers.db',
location: 'default',
})
.then((db: SQLiteObject) => {
this.database = db;
this.storage.get('database_filled').then(val => {
if (val) {
this.databaseReady.next(true);
} else {
this.fillDatabase();
}
})
})
})
}
您必须 return 从第一个 then
开始的承诺。由于您没有 return 从第一个 then
开始,它将 return undefined
。尝试这样的事情。
this.plateform.ready().then(() => {
return this.sqlite.create({
name: 'developers.db',
location: 'default',
})
.then((db: SQLiteObject) => {
this.database = db;
this.storage.get('database_filled').then(val => {
if (val) {
this.databaseReady.next(true);
} else {
this.fillDatabase();
}
})
})
})
我想将创建 SQLite 数据库的结果分配给 SQLiteObject 类型的变量数据库,因此我必须在 "then" 块中执行此操作,但它显示
error ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'then' of undefined.
关于这个错误的大部分文章我都试过了"ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'then' of undefined" 但是 none 个是我的答案
constructor(public http: Http,
private sqlitePorter: SQLitePorter,
private storage: Storage,
private sqlite: SQLite,
private plateform: Platform) {
this.databaseReady = new BehaviorSubject(false);
this.plateform.ready().then(() => {
this.sqlite.create({
name: 'developers.db',
location: 'default',
})
.then((db: SQLiteObject) => {
this.database = db;
this.storage.get('database_filled').then(val => {
if (val) {
this.databaseReady.next(true);
} else {
this.fillDatabase();
}
})
})
})
}
您必须 return 从第一个 then
开始的承诺。由于您没有 return 从第一个 then
开始,它将 return undefined
。尝试这样的事情。
this.plateform.ready().then(() => {
return this.sqlite.create({
name: 'developers.db',
location: 'default',
})
.then((db: SQLiteObject) => {
this.database = db;
this.storage.get('database_filled').then(val => {
if (val) {
this.databaseReady.next(true);
} else {
this.fillDatabase();
}
})
})
})