A little clarity on getting key values using AngularFire v2?

前端 未结 3 601
情深已故
情深已故 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:03

    I believe I am / was experiencing the same issue. Hopefully this is related to your experience. Namely:

    $scope.items = $firebase(new Firebase("https://xxxxxx.firebaseio.com"));
    $scope.items.$on('loaded', function() {
      console.log($scope.items['some key']); // this writes undefined to console
    });
    

    What I noticed is that this actually does work if I don't rely on the loaded event. E.g in the HTML:

    click me
    

    and in the JS:

    $scope.items = $firebase(new Firebase("https://xxxxxx.firebaseio.com"));
    $scope.logItem = function() {
      console.log($scope.items['some key']); // this works
    }
    

    Clicking on the "click me" link logs my item to the console as expected.

    Feels like the collection at loaded time isn't fully populated with the underlying items from firebase.

提交回复
热议问题