Не могу получить значения объекта из Firebase - PullRequest
0 голосов
/ 05 мая 2018

В проекте Angular 5 + Firebase (AngularFire) у меня есть сервис Current, где я получаю текущие пользовательские данные из Firebase RDB:

  export class CurrentService {

  public current;

  constructor(
    private authFb: AngularFireAuth,
    private db: AngularFireDatabase
  ) {
    this.isLoggedIn().pipe(
      tap(user => {
        if (user) {
          this.current = this.db.object(`users/${user.uid}`)
          .valueChanges()
        } else {
          this.current = null;
          console.log("no")
        }
      })
    )
    .subscribe()
  }

  isLoggedIn() {
    return this.authFb.authState.pipe(first())
  }
}

И ввиду этого я хочу связать current значения:

{{ currService.current?.username }}

Но его возвращение null. Что странно, потому что когда я связываю {{ (currService.current | async) | json }}, он возвращает полный объект с полями и значениями в формате json. Что я сделал не так?

1 Ответ

0 голосов
/ 05 мая 2018

Вы также должны использовать трубу async:

{{ (currService.current | async)?.username }}
...