Angularfire在$push后获得唯一id

Angularfire get unique id after $push

本文关键字:唯一 id push Angularfire      更新时间:2023-09-26

我需要在$push 之后获得唯一ID

fb.$push({
  fieldOne: 'monkey moo',
  fieldTwo: 'show',
  insertTime: Firebase.ServerValue.TIMESTAMP
});
then(get -K3Vevty-NtQ30wdJAUw)

我需要的是唯一的id,如"-K3Vevty-NtQ30wdJAUw"

没有.$push(),但有一个.$save(),它返回一个添加了新记录的promise。

var list = $firebaseArray(ref);
list.$add({ foo: "bar" }).then(function(ref) {
  var id = ref.key();
  console.log("added record with id " + id);
  list.$indexFor(id); // returns location in the array
});

阅读文档了解更多信息。