Я получаю приведенную ниже ошибку при чтении данных из firebase.
Ошибка: Uncaught (в обещании): TypeError: Невозможно прочитать свойство 'список' из неопределенного
Я создаю класс репозитория со следующейcode.
import { AngularFireDatabase } from 'angularfire2/database';
export class TopListRepository {
topList$;
constructor(private db: AngularFireDatabase) {
this.topList$ = db.list('/TopList');
}
get(listName) {
console.log('Inside Repo class TopListRepository');
console.log('Parameter val: ' + listName);
console.log('DB object: ' + this.db);
return this.db.object('/TopList/' + listName).valueChanges();
}
}
Пока ниже указан мой класс BO,
import { Observable } from 'rxjs';
import { TopListRepository } from '../respository/topListRepository';
import { AngularFireDatabase } from 'angularfire2/database';
export class TopListBO {
topListRepo: TopListRepository;
private db: AngularFireDatabase;
constructor() {}
getTopList(listName) {
const repo = new TopListRepository(this.db);
return repo.get(listName);
}
}
}
Я вызываю этот класс BO из моего метода get класса обслуживания,
get(listName) {
const boClass = new TopListBO();
return boClass.getTopList(listName);
}
ниже подробно об ошибке,
ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'list' of undefined
TypeError: Cannot read property 'list' of undefined
at new TopListRepository (topListRepository.ts:7)
at TopListBO.push../src/app/models/TopListBO.ts.TopListBO.getTopList (TopListBO.ts:13)
at ToplistsService.push../src/app/services/toplists.service.ts.ToplistsService.get (toplists.service.ts:19)
at new TopplayersComponent (topplayers.component.ts:20)
at createClass (core.js:10148)
at createDirectiveInstance (core.js:10033)
at createViewNodes (core.js:11255)
at callViewAction (core.js:11571)
at execComponentViewsAction (core.js:11490)
at createViewNodes (core.js:11283)
at new TopListRepository (topListRepository.ts:7)
at TopListBO.push../src/app/models/TopListBO.ts.TopListBO.getTopList (TopListBO.ts:13)
at ToplistsService.push../src/app/services/toplists.service.ts.ToplistsService.get (toplists.service.ts:19)
at new TopplayersComponent (topplayers.component.ts:20)
at createClass (core.js:10148)
at createDirectiveInstance (core.js:10033)
at createViewNodes (core.js:11255)
at callViewAction (core.js:11571)
at execComponentViewsAction (core.js:11490)
at createViewNodes (core.js:11283)
at resolvePromise (zone.js:814)
at resolvePromise (zone.js:771)
at zone.js:873
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:421)
at Object.onInvokeTask (core.js:4053)
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:420)
at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:188)
at drainMicroTaskQueue (zone.js:595)
defaultErrorLogger @ core.js:1598