使用AngularJs在Firebase中创建用户 [英] Create user in firebase with AngularJs

查看:116
本文介绍了使用AngularJs在Firebase中创建用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是AngularJs,我想在firebase中创建一个用户,然后我写了下面的代码,但是它不工作!

  var myApp = angular.module('myApp',['firebase','ngRoute']); 
myApp.constant('FIREBASE_URL','MY_FIREBASE_URL');
myApp.controller('RegisterController',['$ scope','$ firebaseAuth','FIREBASE_URL',函数($ scope,$ firebaseAuth,FIREBASE_URL){
$ scope.headerTitle =注册表单;
var ref = new Firebase(FIREBASE_URL);
var auth = $ firebaseAuth(ref);
$ b $ 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;
});
}
}]);

提交表单时出现以下错误:在console.firebase中创建的项目.google.com必须使用firebase.google.com/docs/auth/

中的新Firebase身份验证SDK

解决方案对于Firebase 3.x和AngularFire 2.x,您必须初始化Firebase SDK ,方法是将代码段添加到您的html文件中。


$ b <1> 复制代码段




  • 转至您的项目Firebase控制台 https://console.firebase.google.com/project/

  • ,在弹出窗口中点击将Firebase添加到您的网络应用程序

  • 代码片段,它可能看起来像这样:

     < script src =https://www.gstatic.com/firebasejs /3.1.0/firebase.js\"></script> 
    < script>
    //初始化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的底部或其他脚本标记之前。


很有趣!

I'm using AngularJs and I want to create an user in firebase, then I wrote the following code, however it isn't working!

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;
        });
  }
}]);

I get the following error when submit form : Projects created at console.firebase.google.com must use the new Firebase Authentication SDKs available from firebase.google.com/docs/auth/

解决方案

For Firebase 3.x and AngularFire 2.x you have to Initialize the Firebase SDK by adding the code snippet to your html file.

1) Copy the code snippet

  • Go to your Project Firebase Console https://console.firebase.google.com/project/
  • in the main page of your project, click on Add Firebase to your web app
  • in the popup, copy the code snippet, it may look like this:

    <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) Paste the code snippet in your html file.

  • Paste the snippet at the bottom of your HTML or before other script tags.

have fun!

这篇关于使用AngularJs在Firebase中创建用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆