我正在使用 AngularJs,我想在 firebase 中创建一个用户,然后我编写了以下代码,但它不起作用!
var myApp = angular.module('myApp', ['firebase', 'ngRoute']);
myApp.constant('FIREBASE_URL', 'MY_FIREBASE_URL');
myApp.controller('RegisterController', ['$scope', '$firebaseAuth', 'FIREBASE_URL', function($scope, $firebaseAuth, FIREBASE_URL) {
$scope.headerTitle = "Registration Form";
var ref = new Firebase(FIREBASE_URL);
var auth = $firebaseAuth(ref);
$scope.register = function() {
auth.$createUser({
email: $scope.user.email,
password: $scope.user.password
}).then(function(regUser) {
$scope.message = $scope.user.firstName + " " + $scope.user.lastName + " " + "welcome !";
}).catch(function(error) {
$scope.message = error.message;
});
}
}]);
提交表单时出现以下错误:Projects created at console.firebase.google.com must use the new Firebase Authentication SDKs available from firebase.google.com/docs/auth/
最佳答案
对于 Firebase 3.x 和 AngularFire 2.x,您必须通过将代码段添加到 html 文件来初始化 Firebase SDK。
1) 复制代码片段
- 转到您的 Project Firebase 控制台 https://console.firebase.google.com/project/
- 在项目的主页中,点击将 Firebase 添加到您的网络应用
在弹出窗口中,复制代码片段,它可能如下所示:
<script src="https://www.gstatic.com/firebasejs/3.1.0/firebase.js"></script> <script> // Initialize Firebase var config = { apiKey: " ** your key ** ", authDomain: "your-domain.firebaseapp.com", databaseURL: "https://your-domain.firebaseio.com", storageBucket: "your-domain.appspot.com", }; firebase.initializeApp(config); </script>
2) 将代码片段粘贴到您的 html 文件中。
- 将该代码段粘贴到 HTML 底部或其他脚本标记之前。
玩得开心!
关于javascript - 使用 AngularJs 在 firebase 中创建用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38170665/