我尝试使用Firebase和Ionic构建聊天应用程序。Firebase没有从数据库获得价值
如果我直接打开我的聊天页面通过类似网址:
http://localhost:8100/#/home/messaging/jJ53KWgqnuWXSzksRYl1XNw20JJ2
火力地堡似乎并没有正常工作。但是,如果我从前一页的菜单打开聊天页面:
ui-sref="home.messaging({id: p.friendId})"
一切工作正常。
这是我在ChatController代码:
$scope.data.friendId = $stateParams.id;
var refMessage = firebase.database().ref();
refMessage.child("user_profile").child($scope.data.friendId).once("value")
.then(function (profile) {
$scope.data.friendUserProfile = profile.val();
//on debug this line is reached
});
refMessage.child("profile_photo").child($scope.data.friendId).once("value")
.then(function (profilePic) {
$scope.data.friendUserPhotos = profilePic.val();
//I can't get friend's photos firebase doesnt reach this line.
});
refMessage.child("friends").child($localStorage.uid).child($scope.data.friendId).once("value")
.then(function (friend) {
if (friend.val() !== null) {
$scope.data.isNewFriend = friend.val().isNew;
//on debug this line is reached
}
});
var chatId = 'chat_' + ($scope.data.uid < $scope.data.friendId ? $scope.data.uid + '_' + $scope.data.friendId : $scope.data.friendId + '_' + $scope.data.uid);
的问题是只与朋友共享照片。 Firebase不会从数据库中调用照片。所有其他调用都可以很好地实现异步,但从来没有达到在调试时获取照片的功能。
如果我刷新页面,并且如果转到上一页并返回聊天页面,一切正常,则会出现此问题。
我想如果我的$scope.data
有问题。它不适用于以前的调用friendUserProfile
,但它适用于它。
火力地堡v3.6.1
感谢
谢谢我现在试试这个 – cgrgcn
它没有扔任何东西。就像等待Firebase响应一样,不会从那里返回。 – cgrgcn