Angularfire 在 $push 之后获得唯一 ID

Angularfire get unique id after $push

我需要在 $push

之后获取唯一 ID
fb.$push({
  fieldOne: 'monkey moo',
  fieldTwo: 'show',
  insertTime: Firebase.ServerValue.TIMESTAMP
});
then(get -K3Vevty-NtQ30wdJAUw)

我需要的是唯一的 ID,例如“-K3Vevty-N​​tQ30wdJAUw”

没有 .$push() 但有一个 .$save() returns 添加了新记录的承诺。

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
});

Read the docs 了解更多信息。