firebase.database引用不起作用

时间:2016-07-19 03:27:30

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

我正在尝试在我的离子项目中使用firebase实时数据库。出于某种原因,我在初始化firebase应用程序后无法访问数据库。我添加了firebase-app和firebase-database CDN,但它似乎仍无法正常工作。 我的index.html的head标签看起来像:

<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>

<!-- Firebase -->
<script src="https://www.gstatic.com/firebasejs/3.1.0/firebase.js"></script>

<script src="lib/ionic/js/ionic.bundle.js"></script>

<!-- AngularFire -->
<script src="https://cdn.firebase.com/libs/angularfire/2.0.1/angularfire.min.js"></script>

<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>

<!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
<link href="css/ionic.app.css" rel="stylesheet">
-->

<script src="https://www.gstatic.com/firebasejs/3.1.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/3.1.0/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/3.1.0/firebase-database.js"></script>

<script>
  // Initialize Firebase
  var config = {
    apiKey: "api-key",
    authDomain: "domain",
    databaseURL: "url",
    storageBucket: "bucket",
  };
  firebase.initializeApp(config);
</script>

<script src="js/app.js"></script>
<script src="js/controllers.js"></script>
<script src="js/routes.js"></script>
<script src="js/services.js"></script>
<script src="js/directives.js"></script>

<link href="lib/ionic/css/ionic.css" rel="stylesheet">

我正在尝试实现的功能是我使用模式提交一个在点击时有addRide方法的表单:

 .controller('homeCtrl', function($scope, $firebaseAuth, $firebaseArray) {
  $scope.authObj = $firebaseAuth();
  var dref = firebase.database().ref().child("rides");
  $scope.rides = $firebaseArray(dref);
  $scope.addRide = function(){
    $scope.rides.$add({
      //object
    })
   }
  })

编辑:

将模态控制器与其父页面分开后,它才起作用。我可以使用add添加对象,但由于某种原因,webstorm intellisense仍未获取数据库()。

0 个答案:

没有答案