controller.js
ctx.Get("database").(*gorm.DB)
services.js
angular.module('starter.controllers', ['ionic','ngCordova','forceng'])
// LocalStorage
.controller('warehouseCtrl', ['$scope', '$stateParams', 'reservationService',
function ($scope, $stateParams, reservationService) {
$scope.warehouse =[];
// list all data from Reservation.json
reservationService.all().then(function(warehouseArray){
for (var i = 0; i <warehouseArray.length; i++){
p={"warehouse":warehouseArray[i].warehouse,
"Price":warehouseArray[i].Price
};
$scope.warehouse.push(p);
}
})
}])
// Reservation submit button
.controller('submitCtrl', ['$scope', '$stateParams', '$http','fireBaseService' ,'$localStorage',
function($scope, $stateParams, $http, fireBaseService, $localStorage){
$scope.reservation = {"name": null, "ic": null, "email":null, "phone":null, "address":null, "warehouse":null, "startDate": new Date(), "endDate": new Date, "remark":null};
$scope.submit = function(){
console.log($scope.reservation.name, $scope.reservation.ic, $scope.reservation.email, $scope.reservation.phone, $scope.reservation.address, $scope.reservation.warehouse, $scope.reservation.startDate, $scope.reservation.endDate, $scope.reservation.remark);
fireBaseService.signinUser();
fireBaseService.save($scope.reservation.name, $scope.reservation.ic, $scope.reservation.email , $scope.reservation.phone, $scope.reservation.address, $scope.reservation.warehouse, $scope.reservation.startDate.toLocaleDateString("en-US"), $scope.reservation.endDate.toLocaleDateString("en-US"), $scope.reservation.remark);
$scope.reservation = {"name": null, "ic": null, "email":null, "phone":null, "address":null, "warehouse":null, "startDate": new Date(), "endDate": new Date, "remark":null};
}
}
])
制表reservation.html
angular.module('starter.services', ['ngStorage'])
// Reservation Service
.factory('reservationService', ['$http',
function($http) {
var reservation = [];
return {
all: function(){
return $http.get('Reservation.json').then(function(response){
reservation = response.data;
return reservation;
});
},
}
}])
//firebase service
.factory('fireBaseService', [ '$localStorage',
function($localStorage){
var config = {
apiKey: "AIzaSyA41FxVS8TFpO_s5aIXFhmX5s9Pz88z5Wc",
authDomain: "emob-823c4.firebaseapp.com",
databaseURL: "https://emob-823c4.firebaseio.com",
storageBucket: "emob-823c4.appspot.com",
messagingSenderId: "1092245519317"
};
firebase.initializeApp(config);
// Get a reference to the database service
var database = firebase.database();
$storage = $localStorage.$default({
firebaseArray: []
});
return{
createUser: function(){
firebase.auth().createUserWithEmailAndPassword(email, password).catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
console.log(error.code, error.message);
});
},
signinUser: function(){
firebase.auth().signInWithEmailAndPassword('xxx@gmal.com', '123').catch(function(error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
console.log(error.code, error.message);
});
},
signoutUser: function(){
firebase.auth().signOut().then(function() {
console.log('Sign out successful');
}, function(error) {
console.log(error);
});
},
save: function(name, ic, email , phone, address, warehouse, startDate, endDate, remark){
firebase.database().ref('registration/' + ic).set({
name: name,
ic: ic,
email: email,
phone: phone,
address: address,
warehouse: warehouse,
startDate: startDate,
endDate: endDate,
remark: remark
});
}
}
}])
;
我设法通过我的PC网络浏览器将新数据插入到firebase中,然而,一旦我在我的Android设备上运行它,我就无法检索我的本地存储数据,也无法将任何数据插入到firebase中。谢谢你