【发布时间】:2020-09-18 09:31:51
【问题描述】:
我无法显示 db 中的特定元素。
//component.html
<section class="firee">
<figure class="snip1208">
<div *ngFor="let scholarship of scholarships" >
<h3>{{scholarship.title}}</h3>
<p>{{scholarship.description}}</p>
</div>
</figure>
</section>
//component.ts
import { Component, OnInit } from '@angular/core';
import {AngularFireDatabase} from 'angularfire2/database';
@Component({
selector: 'app-scholarship',
templateUrl: './scholarship.component.html',
styleUrls: ['./scholarship.component.css']
})
export class ScholarshipComponent implements OnInit {
scholarships: any[];
constructor(db: AngularFireDatabase){
db.list('scholarships')
.valueChanges()
.subscribe(scholarships => {
this.scholarships = scholarships;
console.log(this.scholarships); });
}
ngOnInit(): void {
}
}
这是工作
但是当我输入时,例如
<div *ngFor="let scholarship of scholarships" >
<h3>{{scholarship.3}}</h3>
</div>
这行不通。我也尝试过“first_post”,但也不起作用
【问题讨论】:
-
看到
[object Object]渲染了吗? -
如果我把是的,但使用 .title 和 .description 呈现所有上下文表格数据库
{{scholarship}}
-
所以你可以渲染属性?你能说一下到底是什么问题吗?
-
我无法从 db 渲染一个块。例如只有3.title(你可以在截图上看到)
-
去掉
*ngFor,直接渲染。试试:<h3>{{scholarships?.3}}</h3>。删除封闭的div标签。
标签: angular firebase firebase-realtime-database angularfire2