Firebase 数组未在 AngularJS 视图中呈现

Firebase Array not Rendering in AngularJS View

在我的 "User" 服务更新了查看所需的信息后,是什么阻止了我的视图呈现?

伪代码:

  1. User signs in and the profile.uid information should be set. The profile.uid is later used as a child in my Firebase path.
    .factory('User', function (FirebaseUrl, $firebaseArray) {
        var o = {};

        o.setUser = function(authData) {
             o.profile.uid = authData.uid;
        }
        o.getProfile = function() {
            return o.profile;
        }
        return o;
    }
  1. Using $state.go('view') with Angular UI-Router I go to the following view:

控制器:

.controller('viewCtrl', function ($scope, User, $firebaseArray, FirebaseUrl) {

    var profile = User.getProfile();

    //if I hardcore "facebook:213032130516" in the .child(), everything renders correctly...

    var messagesRef = new Firebase(FirebaseUrl + 'user_meta/').child(profile.uid);
    var query = messagesRef.orderByChild("timestamp").limitToLast(5);

    $scope.list = $firebaseArray(query);
}

HTML:

<div ng-repeat="dog in list">
     <h2> {{dog.key}}</h2>
</div>

就目前情况而言,视图未呈现。没有记录任何错误,只是视图是空白的。根据控制器代码中的注释,当我对 .child(profile.uid) 进行硬编码时,它变为 .child('facebook:112351),视图正确呈现。

有人可以帮助我提供更好的实施解决方案,并最终解决为什么这不起作用吗?

谢谢!

您的用户工厂中有一个未定义的 authData

仅通过查看这两段代码很难100% 确定,但我假设您在其他地方调用setUser 时不会传递数据。尝试将其注销并查看丢失的位置。你有我们可以查看的这个项目的 github 回购协议吗?