[英]Why won't all the data get displayed on the browser even though all data is being displayed in console.log()?
[英]Why are values in the console but not being displayed in the page?
值不显示在页面上,但显示在 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>
//火力基地
正如@Peter Haddad 提到的,您必须在列表中添加{{post}}
而不是{{post.$value}}
,如下所示:
<ul>
<li *ngFor="let post of posts">
{{post}}
</li>
</ul>
有关它的更多信息: https://angular.io/guide/displaying-data#add-logic-to-loop-through-data
我希望它有所帮助::)
<ul>
<li *ngFor="let post of posts">
{{post}}
</li>
</ul>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.