Ionic / Firebase聊天应用消息未被退回

时间:2015-06-30 21:54:23

标签: angularjs web-applications firebase chat ionic

我是firebase的新手并且正在遵循使用ionic创建一个简单的聊天应用程序的教程,但是我似乎无法获得返回并显示的消息。 这是我的Index.html以及我的app.js我似乎找不到什么错误。

<!DOCTYPE html>
<html>
<head>

<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<link href="css/ionic.app.css" rel="stylesheet">
-->




<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>

<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>

<!-- your app's js -->
<script src="js/app.js"></script>
<!-- Firebase -->
<script src="https://cdn.firebase.com/js/client/2.0.4/firebase.js"></script>
<!-- AngularFire -->
<script src="js/angularfire.min.js"></script>
</head>
<body ng-app="starter" ng-controller="chatController">
<ion-header-bar class="bar-stable">
<h1 class="title">My Anonymous Chat App</h1>
</ion-header-bar>
<ion-content class="has-subheader">
<div class="row row-bottom">
<div class="col">
<div class="chatbox-container">
<ul class="chatbox">
<!-- We output the messages -->
<li ng-repeat="message in messages">{{messages.content}}       </li>
</ul>
</div>
<form name="myform" ng-submit="addMessage(message.theMessage)">
<label class="item item-input message-input">
<!-- the input text field is bound to message.theMessage -->
<input type="text" ng-model="message.theMessage"
placeholder="Type your message..."></input>
</label>
<button class="button button-block button-dark" action="submit"> Send
</button>
</div>
</div>
</ion-content>
</body>
</html>

和我的app.js

angular.module('starter', ['ionic', 'firebase'])

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    // Hide the accessory bar by default (remove this to show the accessory bar 

above the keyboard
    // for form inputs)
    if(window.cordova && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
    }
    if(window.StatusBar) {
      StatusBar.styleDefault();
    }
  });
})
.controller('chatController', ["$scope", "chatMessages", function($scope, chatMessages ) {
    //Set messages to chatMessages factory which returns the firebase data
    $scope.messages = chatMessages;

    //Initialize message object
    $scope.message = {};

    //Add message to the firebase data
    $scope.addMessage = function(message) {
      $scope.messages.$add({content: message});
      //we reset the text input field to an empty string
      $scope.message.theMessage = "";
    };
}])
.factory("chatMessages", ['$firebase', "$rootScope", function($firebase, $rootScope){
     // create a reference to the Firebase where we will store our data
     var ref = new Firebase("https://mattschatapp.firebaseio.com/");

     // this uses AngularFire to create the synchronized array
     return $firebase(ref.limitToLast(10)).$asArray();
}]);

0 个答案:

没有答案
相关问题