嗨,我的朋友们我想从Firestore查询文件ID到我的ionic4应用 我可以将文档的ID传递到详细信息页面,而我又不知道如何查询文档的数据。 我的数据库
我尝试过此代码: news.page.html
<ion-content padding>
<ion-item *ngFor=" let count of news | async">
<h5>{{count.title}}<ion-button routerLink="/details/{{count.id}}"> details</ion-button>
<img src="{{count.image}}">
</h5>
</ion-item>
</ion-content>
news.page.ts
news: Observable<any[]>;
constructor(public db: AngularFirestore, private router: Router) { }
ngOnInit() {
this.news = this.db.collection('123').snapshotChanges().map(actions => {
return actions.map(a => {
const data = a.payload.doc.data();
const id = a.payload.doc.id;
return { id, ...data };
});
});
}
details.page.html
<ion-content padding >
{{id}}
</ion-content>
details.pge.ts
export class DetailsPage implements OnInit {
id: string;
constructor(private router: ActivatedRoute, private afs: AngularFirestore) {
}
ngOnInit() {
this.id = this.router.snapshot.paramMap.get('id');
console.log(this.id);
}
}