如何使用AngularFir将用户数据存储到我的用户节点?

时间:2016-05-13 14:35:59

标签: angularjs firebase angularfire firebase-realtime-database firebase-authentication

我创建了我的登录信息,并且已经能够允许用户立即注册。但是我想将用户数据存储到我的节点。我添加了我认为应该在addUser函数中工作的代码。我已经研究了很多年但是找不到解决方案。有人能指出我正确的方向,我做错了吗?

我写的代码如下。提前谢谢。

'use strict';

var theBigWeddingBook = angular.module('theBigWeddingBook');

theBigWeddingBook.controller('RegCtrl', function ($scope, $firebaseAuth,   $firebaseObject)

{
  var ref = new Firebase("https://the-big-wedding-book.firebaseio.com");
  var reg = $firebaseAuth(ref);

$scope.user = {};

$scope.addUser = function() {
    var username = $scope.user.email;
    var password = $scope.user.password;
    var uid = $scope.user.uid;

    reg.$createUser({
        email: username,
        password: password
    }).then(function(user) {
        console.log('User has been successfully created!');
    }).catch(function(error) {
        console.log(error);
    })

    ref.child('user').child(user.uid).set(user).then(function(user) {
        console.log('Data Saved Successfully!');
    }).catch(function(error) {
        console.log(error);
    })
};
})

2 个答案:

答案 0 :(得分:0)

$scope.addUser = function() {

  var uid = $scope.user.uid;

  reg.$createUser({
    email: $scope.user.email,
    password: $scope.user.password
  }).then(function(user) {
     console.log('User has been successfully created!');
  }).catch(function(error) {
    console.log(error);
  })
})

OR

  $scope.addUser = function() {
    var username = $scope.user.email;
    var password = $scope.user.password;
    var uid = $scope.user.uid;

    reg.$createUser({
        email: this.username,
        password: this.password
    }).bind(this)
      .then(function(user) {
        console.log('User has been successfully created!');
    }).catch(function(error) {
        console.log(error);
    })

答案 1 :(得分:0)

我得到了它的工作。我基本上改变它,以便当有人注册时它们会自动登录,然后在身份验证时,数据会保存到用户节点,如下所示。

user> (map-with-reduce inc [1 2 3])
(2 3 4)

user> (map-with-reduce + [1 2 3] [4 5] [6 7 8])
(11 14)