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

后端 未结 1 689
北海茫月
北海茫月 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)
提交回复
热议问题