Get the index ID of an item in Firebase AngularFire

后端 未结 3 878
粉色の甜心
粉色の甜心 2021-02-06 17:25

A similar question was asked here, but the one accepted answer doesn\'t really answer the question.

Using AngularFire, is it possible to to create relational-style datab

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-06 17:46

    In the new version of AngularFire, you can just iterate through the AngularFire object as though it were a normal javascript object.

    $scope.users = {};
    angularFire(ref, $scope, 'users').then(function() {
        for (var id in $scope.users) {
            if ($scope.users.hasOwnProperty(id) {
                ...
            }
        }
    });
    

    I don't think this is really what you want to do though, as you'd be loading all user data into every client. You should probably have the client provide a username or some other kind of id, maybe with Firebase Simple Login.

    Finally, are you familiar with your browser's developer tools? They can be extremely useful for peeking inside of objects you don't know what to do with, like an AngularFire, to see how they're structured internally.

提交回复
热议问题