【问题标题】:Type 'String' has no compatible call signatures类型“字符串”没有兼容的调用签名
【发布时间】:2026-01-22 07:25:02
【问题描述】:

我正在尝试使用 Firebase 和 AngularFire2 执行 multi-path update。但是,当我使用这个时,我得到了上面的错误:

let fb = firebase.database().ref();
let key = fb.child('/path').push().key();

有什么想法可以在使用 AngularFire2 推送某些内容后获取密钥吗?

【问题讨论】:

    标签: typescript firebase firebase-realtime-database angularfire2


    【解决方案1】:

    由于push 方法现在返回一个 Observable,因此获取生成的$key(使用 AF2)的正确方法是执行以下操作:

    let fb = this.af.database.list('/path');
    fb.push('item').then(res => console.log(res.key));
    

    【讨论】: