由于某种原因,将Firebase键加入功能时遇到了一些麻烦。我可以在页面上的其他功能中记录正确的键,但不能在其中之一上登录,我敢肯定我缺少一些简单的东西,但是现在我对原因感到非常困惑。有人可以像我5岁时向我解释吗?
代码:
export class HomePage {
infos = [];
ref = firebase.database().ref('infos/').orderByChild('vote');
constructor(private route: ActivatedRoute, public router: Router, public alertController: AlertController) {
this.ref.on('value', resp => {
this.infos = [];
this.infos = snapshotToArray(resp);
});
}
edit(key) {
this.router.navigate(['/edit/'+key]);
console.log(key); <----- correct key here--
}
async delete(key) {
console.log(key); <-------correct key here ---
const alert = await this.alertController.create({
header: 'Confirm!',
message: 'Are you sure want to delete this info?',
buttons: [
{
text: 'Cancel',
role: 'cancel',
cssClass: 'secondary',
handler: (blah) => {
console.log('cancel');
}
}, {
text: 'Okay',
handler: () => {
firebase.database().ref('infos/'+key).remove();
}
}
]
});
await alert.present();
}
upvote(key) {
console.log(key); <------Undefinded Key????---
};
当我尝试在“ Upvote”功能中返回键时,它返回未定义的,但是其他所有内容都返回正确的键。我在这里想念什么?
编辑:
<ion-button (click)="upvote(key)">Upvote</ion-button>
<ion-button (click)="downvote(key)">Downvote</ion-button>