Angular CLI:13.0.4 ionic --version => 6.20.2
你好!我對 Ionic / Angular / Firebase 有點陌生。我使用 Firebase firestore 作為我的資料庫,我已經創建了集合并用資料填充了它。在頁面上顯示集合中的單個檔案的最簡單解決方案是什么?目前我堅持將其寫入控制臺并且無法在 HTML 上顯示它。經過數小時的搜索,我希望有人可以幫助我解決這個問題。
`
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import {AngularFirestore} from "@angular/fire/compat/firestore";
@Component({
selector: 'app-first-place',
templateUrl: './first-place.page.html',
styleUrls: ['./first-place.page.scss'],
})
export class FirstPlacePage implements OnInit {
constructor(
private router: Router,
private afs: AngularFirestore,
) {}
ngOnInit() {
this.afs.collection('rentplace').valueChanges()
.subscribe(value => console.log(value[0]));
}
}
` 從控制臺我得到這個輸出:{rentplaceTitle:'第二頁',rentplaceHref:'secondref',rentplaceWaterBike:44,rentplaceSup:50,rentplaceOwnerEmail:'[email protected]',...}
我試過切割陣列,但每次我在 HTML 中參考它時,我只得到結果。
uj5u.com熱心網友回復:
只需獲取您收到的內容并使用JsonPipe將其顯示為 Json 格式即可除錯您的回應物件。
first-place.page.html
<div>
{{content | json}}
</div>
first-place.page.js
.....
content: any;
ngOnInit() {
this.afs.collection('rentplace').valueChanges()
.subscribe(value => this.content = value);
}
.....
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/527602.html
