【问题标题】:Use Firebase SDK 3 with Ionic 1.X将 Firebase SDK 3 与 Ionic 1.X 一起使用
【发布时间】:2016-12-18 17:20:27
【问题描述】:

我正在 ionic 1.X 中构建聊天,我想使用 Firebase 作为我的数据库和身份验证提供程序。首先,我希望能够使用 Firebase 创建和登录用户。我在我的帐户中启用了简单的电子邮件和密码身份验证。但是,大多数像 one 这样的教程都适用于 Firebase 2。如果我遵循它,我会遇到下一个错误:

在我的 index.html 中,我像这样加载 firebase:

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

然后创建一个用户:

  $scope.signupEmail = function(){
    $scope.message = null;
    $scope.error = null;

    console.log('In signup email with username ' +  $scope.data.username + ' email ' + $scope.data.email + ' and password ' + $scope.data.password);
    var chatRef = new Firebase('https://some-url.firebaseio.com');
    var auth = $firebaseAuth(chatRef);
    auth.$createUser({
      email: $scope.data.email,
      password: $scope.data.password
    }).then(function(userData) {
        console.log("User created with uid: " + userData.uid);
        $scope.message = "User created with uid: " + userData.uid;
      }).catch(function(error) {
        console.log("Error: " + error);
        $scope.error = error;
      });

  };

合乎逻辑的结论和搜索谷歌是我应该使用 Firebase 3 SDK 来创建用户。但是,如果我转到 index.html 并添加使用 firebase 的新方法,在官方 Ionic 文档(不是旧文档)中,您可以找到任何将新 SDK 与 Ionic 集成的部分:

 <script src="https://www.gstatic.com/firebasejs/3.1.0/firebase.js"></script>
  <script>
    // Initialize Firebase
    // TODO: Replace with your project's customized code snippet
    var config = {
      apiKey: "apiKey",
      authDomain: "projectId.firebaseapp.com",
      databaseURL: "https://databaseName.firebaseio.com",
      storageBucket: "bucket.appspot.com",
    };
    firebase.initializeApp(config);
  </script>

然后我无法将“firebase”注入我的模块。

知道如何集成 firebase sdk 3 和 ionic 1.x 吗?

【问题讨论】:

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


    【解决方案1】:

    您似乎在使用 1.2.0 版的 angularfire - 您的 index.html 包含 .../angularfire/1.2.0/angularfire.min.js

    该版本不支持 Firebase 3。但是,angularfire 的更新版本支持:version 2.0.0

    还有一个migration guide 可能更容易将您找到的教程中的信息外推到 Firebase 3。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-05
      • 2019-10-23
      • 2019-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-06
      相关资源
      最近更新 更多