0
獲取這種類型的數據水平您好所有如何從火力
是新的火力點和離子和我創建聊天應用程序,將 讓我的應用程序用戶能夠直接與聊天另一個,我有 成功地能夠註冊用戶;獲取用戶,也已經 能消息中的每個用戶,但我的地方混亂的是我應該如何去 顯示消息
這裏是我的火力地堡結構
這裏是我的看法代碼
<ion-view view-title="Home Page">
<ion-content delegate-handle="show-page" >
<!-- Loading Indicator -->
<div class="loading"
ng-if="data.loading" >
<ion-spinner icon="ripple" ></ion-spinner >
<p >Loading messages...</p >
</div >
<!-- Empty room message -->
<div class="loading"
ng-show="!data.loading && data.message.length == 0" >
<p >This room is empty, be the first to post!</p >
</div >
<!-- Discussion list -->
<div class="chat-messages">
<ul>
<li ng-repeat="data in chatMessages">
{{data.message}}
</li>
</ul>
</div>
</ion-content>
<ion-footer-bar keyboard-attach
class="bar-assertive item-input-inset" >
<label class="item-input-wrapper" >
<input type="text"
placeholder="Type your message"
ng-enter="sendMessage()"
ng-model="data.message" />
</label >
<button class="button button-clear"
ng-click="sendMessage()" >
Send
</button >
</ion-footer-bar >
,這裏是我的控制器
app.controller('chatCtrl', function ($scope, $state, $stateParams, $localStorage) {
$scope.data = {
messages: [],
message: '',
loading: true,
showInfo: false
};
var to = $stateParams.UserName;
$localStorage.from = $stateParams.MyName;
var roomName = 'chat_'+(to<$localStorage.from ? to+'_'+$localStorage.from : $localStorage.from+'_'+to);
console.log(to+', '+$localStorage.from+' => '+ roomName);
var messagesRef = new Firebase("https://bigzill.firebaseio.com/chatMessages/"+roomName);
$scope.loadMessages = function() {
$scope.data.messages =$firebaseArray(messagesRef);
$scope.data.messages.$loaded().then(function(data){
console.log("Angular fire $loaded");
$scope.data.loading =false;
$ionicScrollDelegate.$getByHandle('show-page').scrollBottom(true);
});
};
$scope.sendMessage = function(){
var to = $stateParams.UserName;
$localStorage.from = $stateParams.MyName;
var from = $stateParams.MyName;
var dataToDb = {from: from, to: to, message: $scope.data.message,timestamp: new Date().getTime()};
var roomName = 'chat_'+(to<from ? to+'_'+from : from+'_'+to);
var InsertChatRef = new Firebase('https://bigzill.firebaseio.com');
var insertObj =InsertChatRef.child('chatMessages').child(roomName);
insertObj.push(dataToDb);
$scope.data.message = '';
};
});
好吧,這是我已經能夠得到的,我只是去beneth我的'$ scope.loadMessages =函數(){...}'和我添加了這個代碼''scope.loadMessages();'當我重新加載我的瀏覽器時,我看到的只是**這個房間是空的,是第一個發佈!**但相信我我已經添加了我的消息它...... **請問是什麼做錯了** – user3728868