【问题标题】:AngularJS and Firebase, trouble adding data in $firebaseArrayAngularJS 和 Firebase,在 $firebaseArray 中添加数据时遇到问题
【发布时间】:2017-02-18 19:21:40
【问题描述】:

我对 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);
}

【问题讨论】:

    标签: angularjs ionic-framework firebase-realtime-database


    【解决方案1】:

    您可能没有将控制器链接到 index.html 中的代码。 (使用 ng-controller 指令)

    【讨论】:

      猜你喜欢
      • 2018-03-18
      • 1970-01-01
      • 1970-01-01
      • 2018-04-25
      • 1970-01-01
      • 2019-12-24
      • 2023-01-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多