【问题标题】:Firebase Angular9Firebase Angular 9
【发布时间】: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”,但也不起作用

这里是 db

【问题讨论】:

  • 看到[object Object] 渲染了吗?
  • 如果我把

    {{scholarship}}

    是的,但使用 .title 和 .description 呈现所有上下文表格数据库
  • 所以你可以渲染属性?你能说一下到底是什么问题吗?
  • 我无法从 db 渲染一个块。例如只有3.title(你可以在截图上看到)
  • 去掉*ngFor,直接渲染。试试:&lt;h3&gt;{{scholarships?.3}}&lt;/h3&gt;。删除封闭的div 标签。

标签: angular firebase firebase-realtime-database angularfire2


【解决方案1】:

我想你可能需要:

<h3>{{scholarship[3].title}}</h3>

或者

<h3>{{scholarship["3"].title}}</h3>

【讨论】:

    猜你喜欢
    • 2020-09-05
    • 2020-09-02
    • 2020-08-04
    • 2021-07-28
    • 1970-01-01
    • 2020-10-07
    • 2020-08-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多