A little clarity on getting key values using AngularFire v2?

前端 未结 3 589
情深已故
情深已故 2021-02-11 08:52

Sorry for the length of this but it\'s driving me a little bit crazy:

Let\'s say I want to get an item\'s \"title\" and \".priority\" key values when it loads.

F

3条回答
  •  孤城傲影
    2021-02-11 09:23

    The $child method should only be used to create a new AngularFire reference. Calling $child is the same as calling $firebase(new Firebase(parentULR + "/childName")). In your example, if all you are trying to do is to get the $priority and title for a given object, you can simply do:

    $scope.items = $firebase(new Firebase("https://****.firebaseio.com"));
    $scope.items.$on('loaded', function() {
      var item = $scope.items['your-item-id'];
      console.log(item['$priority']);
      console.log(item.title);
    });
    

    If you don't know the ID of your item, you can iterate over the $scope.items object to find it if you'd like.

提交回复
热议问题