如何在 Ionic 2 中直接获取添加的 firebase 项目的 id/key?

How to get the id/key of added firebase item directly in Ionic 2?

我正在尝试在添加处理后获取添加项的 id/key

例如,这是我的添加函数

add(){
    let todayTime = moment().format('YYYY-MM-DD, HH:mm')
    this.afd.list('/questions/').push({
        uemail: this.userService.email,
        title: this.variables.title,
        text: this.variables.text,
        type: this.variables.type
    })
}

那么如何直接获取id(当项目添加成功时)?

根据 firebase doc

let key = this.afd.list('/questions/').push().key;

您在推送数据之前获得密钥。当您需要使用 .update()

在不同位置同时添加数据时,它很有用