I am trying to send an array object from my Ionic application up into Firebase and I cant figure out where Im going wrong. The array contains information based on what a user has ordered in a bar, like the drink name and the price. I managed to get the array logged on the console with this information inside but I dont actually know how I`d go about saving this to Firebase.
This is the service that I have created:
//Order Service
.factory('OrderService', function($firebase, $rootScope){
var ref = new Firebase("https://whatever.firebaseio.com/");
return $firebase(ref.child('orders')).$asArray();
});
This is the controller I have created
.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});
};
And the data I`m trying to capture and send is from this page:
<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>
Im totally new to sending data to Firebase from Ionic and I`d appreciate it if someone could point me in the right direction.
Thanks!!!