【发布时间】:2016-12-15 20:48:45
【问题描述】:
我尝试使用 Firebase 和 Ionic 构建聊天应用程序。
如果我直接通过以下 URL 打开我的聊天页面:
http://localhost:8100/#/home/messaging/jJ53KWgqnuWXSzksRYl1XNw20JJ2
Firebase 似乎无法正常工作。但是,如果我从上一页的菜单中打开聊天页面:
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,但它适用。
Firebase v3.6.1
谢谢
【问题讨论】:
标签: angularjs firebase ionic-framework firebase-realtime-database