火力地堡角 9

Firebase Angular9

我无法显示数据库中的特定元素。

//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",但还是不行

这里是数据库

我想你可能需要:

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

或者

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