Почему значения отображаются в консоли, но не отображаются на странице? - PullRequest
1 голос
/ 28 мая 2020

Значения не отображаются на странице, но отображаются в console.log

//app.components.ts
    import { Component } from '@angular/core';
import {AngularFireDatabase } from 'angularfire2/database';
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  posts: any[];
  constructor(db: AngularFireDatabase){
    db.list('posts').valueChanges().subscribe(posts => {  this.posts = posts; console.log(this.posts); });

  }
}

//app.component.html

    <ul>
  <li *ngFor="let post of posts">
{{post.$value}}
  </li>
</ul>

// firebase

that's my firebase

and here what I have

Ответы [ 2 ]

1 голос
/ 28 мая 2020
<ul>
  <li *ngFor="let post of posts">
{{post}}
  </li>
</ul>
0 голосов
/ 28 мая 2020

Как упомянул @Peter Haddad, вы должны добавить {{post}} вместо {{post.$value}} в список, например:

<ul>
  <li *ngFor="let post of posts">
{{post}}
  </li>
</ul>

Подробнее об этом: https://angular.io/guide/displaying-data#add -logi c -to-l oop -through-data

Надеюсь, это поможет! :)

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...