从firestore onSnapshot返回后,数据未渲染
我在这里使用离子/角前端。我的数据正确地来自Firestore。在对Firestore文件进行了更改后,它也会返回。
但是,数据永远不会呈现到ion-content
。它确实正确地登录到控制台。这使我相信我在离子/角度做错了。
模板文件
<ion-content [fullscreen]="true" style="text-align: center;" *ngIf="!this.isLoading">
<ion-item *ngFor="let team of currentTeams; let index" [color]="team.color" style="margin: 10px;">
<p>{{index}}</p>
<h1 slot="start" style="height: 3.5rem;">{{ team.name }}</h1>
<br />
<div id="controls" slot="end">
<ion-icon style="margin: 0 20px" name="remove-circle" (click)="decrementTeamScore(team)"></ion-icon>
<span>{{ team.score }}</span>
<ion-icon style="margin: 0 20px" name="add-circle" (click)="incrementTeamScore(team)"></ion-icon>
</div>
</ion-item>
</ion-content>
类文件
this.isLoading = true;
this.gameId = this.route.snapshot.params.id;
if(this.gameId) {
const result = await this.getGame();
if(result) {
await this.getTeams();
}
}
this.isLoading = false;
}
public async getTeams() {
const teamRef = this.teamsCollection.ref;
const teamsByGameIdQuery = teamRef.where('gameId', '==', this.currentGame.docID).orderBy('score', 'desc');
onSnapshot(teamsByGameIdQuery, (snapshot) => {
const teams: ITeam[] = [];
snapshot.docs.forEach((doc) => {
teams.push({ ...doc.data(), id: doc.id});
this.currentTeams = teams;
});
console.log(this.currentTeams);
});
}
I am using an Ionic/Angular frontend here. My data comes back from Firestore correctly. It also comes back after a change has been made to the firestore document.
However, the data never renders to the ion-content
. It does log to the console correctly. This leads me to believe I am doing something wrong with Ionic/Angular.
The template file
<ion-content [fullscreen]="true" style="text-align: center;" *ngIf="!this.isLoading">
<ion-item *ngFor="let team of currentTeams; let index" [color]="team.color" style="margin: 10px;">
<p>{{index}}</p>
<h1 slot="start" style="height: 3.5rem;">{{ team.name }}</h1>
<br />
<div id="controls" slot="end">
<ion-icon style="margin: 0 20px" name="remove-circle" (click)="decrementTeamScore(team)"></ion-icon>
<span>{{ team.score }}</span>
<ion-icon style="margin: 0 20px" name="add-circle" (click)="incrementTeamScore(team)"></ion-icon>
</div>
</ion-item>
</ion-content>
The class file
this.isLoading = true;
this.gameId = this.route.snapshot.params.id;
if(this.gameId) {
const result = await this.getGame();
if(result) {
await this.getTeams();
}
}
this.isLoading = false;
}
public async getTeams() {
const teamRef = this.teamsCollection.ref;
const teamsByGameIdQuery = teamRef.where('gameId', '==', this.currentGame.docID).orderBy('score', 'desc');
onSnapshot(teamsByGameIdQuery, (snapshot) => {
const teams: ITeam[] = [];
snapshot.docs.forEach((doc) => {
teams.push({ ...doc.data(), id: doc.id});
this.currentTeams = teams;
});
console.log(this.currentTeams);
});
}
Also including the console data that I am getting back from Firestore.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,我看到,始终会出现错误的问题,我只需删除HTML标签(P,HR,DIV),然后使用离子自己的组件,例如离子贴,离子卡等。
在
。
Ok I see, always this errors cames to me, I just remove HTML tags (p, hr, div) and use Ionic own components, like ion-title, ion-card, and so on.
Find more on https://ionicframework.com/docs/components
Thanks !