从Ionic App向Firebase发送数组

时间:2015-04-06 22:09:05

标签: arrays angularjs firebase ionic-framework ionic

我正在尝试将一个数组对象从我的Ionic应用程序发送到Firebase,我无法弄清楚我哪里出错了。该数组包含基于用户在栏中订购的内容的信息,例如饮品名称和价格。我设法在控制台上记录了这些信息,但我实际上并不知道如何将其保存到Firebase。

这是我创建的服务:

//Order Service
.factory('OrderService', function($firebase, $rootScope){

 var ref = new Firebase("https://whatever.firebaseio.com/");
    return $firebase(ref.child('orders')).$asArray();
  });

这是我创建的控制器

   .controller('DrinkCtrl', function ($scope, $ionicListDelegate,$ionicLoading, $ionicModal, $ionicPopup, MenuService, OrderService) {

      $scope.orders = OrderService;
      $scope.order = {};

     $scope.addOrder = function(order){
     $scope.orders.$add({content: $scope.order});
  };

我试图捕获和发送的数据来自此页面:

  <ion-modal-view>
        <ion-header-bar class="bar-energized">
           <div class="buttons">
             <button class="button button-energized" ng-click="cancelPreview()">Cancel</button>
           </div>
             <h1 class="title">Preview Order</h1>
           <div class="buttons">
              <button class="button button-energized" ng-if="order.items.length"  ng-model="order.theOrder" ng-click="sendOrder()" action="submit">Submit</button>
           </div>
          </ion-header-bar>
        <form name="myform" ng-submit="addOrder(order.theOrder)">
         <ion-content>
         <div style="height: 60px;"></div>
          <ion-list>
       <ion-item ng-if="!order.items.length" class="item-divider">No items  **strong text**</ion-item>
  <ion-item ng-model="order.theOrder"  ng-repeat="item in order.items">
    {{item.item}} <span class="item-note">{{item.price | currency:"€" }}
    <ion-option-button class="button-assertive" ng-click="remove($index)">Remove</ion-option-button>
  </ion-item>
</ion-list>

我非常擅长从Ionic向Firebase发送数据,如果有人能指出我正确的方向,我会很感激。

感谢!!!

0 个答案:

没有答案