我對AngularJS和Firebase非常陌生。目前在從表單獲取數據並將其放入Firebase時遇到了一些問題。我沒有控制檯日誌,但數據只是一點兒也不進入火力地堡希望某種靈魂可以幫助我:(
的index.html
<!-- Firebase -->
<script src="https://cdn.firebase.com/js/client/2.2.4/firebase.js"></script>
<script src="https://www.gstatic.com/firebasejs/3.6.5/firebase.js"></script>
<script>
// Initialize Firebase
var config = {
apiKey: "x",
authDomain: "x",
databaseURL: "x",
storageBucket: "x",
messagingSenderId: "x"
};
firebase.initializeApp(config);
// Get a reference to the database service
var database = firebase.database();
</script>
<!-- AngularFire -->
<script src="https://cdn.firebase.com/libs/angularfire/2.2.0/angularfire.min.js"></script>
形式(sell.html)
<h1 id="sell-heading4" style="color: rgb(0, 0, 0);">Test</h1> <form ng-submit="appsell()"> <label class="item item-input" id="sell-input4"> <span class="input-label">Input</span> <input placeholder="" type="text" ng-model="name"> </label> <label class="item item-input" id="sell-input4"> <span class="input-label">Input2</span> <input placeholder="" type="text" ng-model="name2"> </label> <button id="sell-button3" class="button button-positive button-block" >Tap me!</button> </form>
controller.js
.controller('sellCtrl', ['$scope', '$stateParams', '$firebaseArray', // The following is the constructor function for this page's controller. See https://docs.angularjs.org/guide/controller
// You can include any angular dependencies as parameters for this function
// TIP: Access Route Parameters for your page via $stateParams.parameterName
function ($scope, $stateParams, $firebaseArray) {
var ref = firebase.database().ref();
$scope.data = $firebaseArray(ref);
$scope.addsell = function(){
$scope.data.$add($scope.name1);
$scope.data.$add($scope.name2);
}