[英]ionic angular : ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'um' of undefined
[英]IONIC 4 + Angular7: ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'then' of undefined
由于这个原因,我想将创建SQLite数据库的结果分配给类型为SQLiteObject的变量数据库,我必须在“然后”块中执行此操作,但它显示
错误错误错误:未捕获(承诺):TypeError:无法读取未定义的属性'then'。
我已经尝试了有关此错误的大多数文章“ ERROR错误:未捕获(承诺):TypeError:无法读取未定义的属性'then'”,但这些都不是我的答案
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();
}
})
})
})
}
您将必须从第一个then
就返还诺言。 当你没有返回从第一个东西then
就会返回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();
}
})
})
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.