![](/img/trans.png)
[英]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.