How do I get the UID of the new list item I just added to Firebase using AngularJS?

后端 未结 1 691
北海茫月
北海茫月 2021-01-17 05:48

I am adding new children to a Firebase list and unique IDs are automatically created. I need some way to get the ID thats been created so I can immediately change the URL l

1条回答
  •  伪装坚强ぢ
    2021-01-17 06:25

    The angularFire $add method returns a promise, which when resolved will contain a Firebase reference to your newly pushed value. With that value, you can get the UID.

    $scope.tests.$add({
      ...your object....
    })
      .then(function(ref) { 
        $location.path("/test/"+ref.name()); 
      });
    

    0 讨论(0)
提交回复
热议问题