我已經寫了一個簡單的應用程序,它利用索引資料的(感謝Robisim他的示例應用程序,其代碼我借https://github.com/robisim74/angular2indexedDB),但我有麻煩訪問對象的數組我的組件是異步的。儘管我可以使用|來在HTML頁面上遍歷ITEMS異步管道 - 我似乎無法使用ts文件中的對象數組。我已經嘗試訂閱observable,但它沒有成功做任何事情。任何人都可以請幫我選擇對象數組中的第一個對象,當observable從IndexedDB加載完成時?訪問可觀察到的流已在角2結束後?
首頁組件
getSchedule(){
this.selectedSchedule = this.entity.schedule[0];
}
得到物品():可觀察{
return new Observable((observer: Observer<Array<Item>>) => {
observer.next(this.entity.schedule);
console.log(this.entity.schedule);
observer.complete();
});
}
代碼在應用COMPONE NT打開DB
openDB(數據庫:字符串){
// Opens the database.
this.indexedDB.openDBAsync(dbName, 1).forEach(
// Next.
(readyState: string) => {
console.log('IndexedDB service: opening db: ' + readyState);
}, null
).then(
() => {
// Gets all records from "TodoStore".
this.indexedDB.getAllRecordsAsync("ItemStore").forEach(
// Next.
(record: Item) => {
// Adds next record to the Todos entity.
if (record != null) {
this.entity.addItem(record);
}
}, null
).then(() => console.log('IndexedDB service: obtaining of all records completed.'))
}
);
}
嘿羅布,非常感謝你回答我的問題。過去幾天我一直在努力實現這個答案。發生的一件事情是,整個應用程序加載到一個空白的白色屏幕,並沒有在控制檯或終端中出現任何錯誤。我查看了APP_INITIALIZER的其他案例,但仍然迷失了方向。 –
我剛剛開始工作!在您的回購應用望去,提供索引資料和它的作品完美,能夠拿起的第一個項目上的應用程序的負載。再次非常感謝! –