我是AngularJS和Firebase的新手。目前在从表单中获取数据并将其放入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);
}
答案 0 :(得分:0)
您可能没有将控制器链接到index.html中的代码中。 (使用ng-controller指令)