如何插入对象插入到火力地堡锻造? - AngularFire 0.8.0 - Thinkster - 第7章 [英] How to insert object into Firebase Forge? - AngularFire 0.8.0 - Thinkster - Chapter 7
问题描述
我下面的Thinkster昂 - 新闻教程安装AngularFire的最新版本(0.8.0)。我已经成功地得到部分7成功教程的但我卡在那里我需要插入一个用户对象到火力地堡伪造的部分。在code的工作原理如下:
I am following the Thinkster Ang-News tutorial with the latest version of AngularFire (0.8.0) installed. I've managed to get to part 7 of the tutorial successfully but I am stuck on the part where I need to insert a user object into the Firebase Forge. The code works as follows:
在通过我的HTML表单中的新用户注册,注册函数被调用和User.create(AUTHUSER,$ scope.user.username);在注册功能中执行。
When a new user registers via my HTML form, the "register" function is called and "User.create(authUser, $scope.user.username);" is executed within the "register" function.
// login and registration page
app.controller('AuthCtrl',
function ($scope, $location, Auth, User) {
if (Auth.signedIn()) {
$location.path('/');
}
$scope.$on('firebaseSimpleLogin:login', function(){
$location.path('/');
});
$scope.login = function(){
Auth.login($scope.user).then(function(){
$location.path('/');
}, function (error){
$scope.error = error.toString();
});
};
$scope.register = function () {
Auth.register($scope.user).then(function (authUser) {
Auth.login($scope.user);//cause creating user auto login
User.create(authUser, $scope.user.username);
console.log(authUser);
$location.path('/');
}, function (error){
$scope.error = error.toString();
});
};
});
用户的服务具有以下功能:创造中创建用户对象和应存储在火力地堡伪造的对象的信息。正如你可以看到下面,用户。$保存(用户名)被称为用户$保存进入火力地堡伪造。然而,什么也没有发生在我火力地堡锻造当$保存方法被调用。我回顾了最新AngularFire规格,并且你可以在我的code注释(//),我试过$ asArray(),$ asObject()与我的用户看到相结合的变量,但没有奏效。当我用的用户$添加(用户名)。而不是调用$保存方法,我的火力地堡伪造刚刚添加的用户名没有对象的属性。
The "User" service has a function "create" which creates the user object and should store the object information in the Firebase Forge. As you can see below, "users.$save(username)" is called to "$save" the user into the Firebase Forge. However, nothing happens in my Firebase Forge when the $save method is called. I reviewed the latest AngularFire specs, and as you can see in my code comments (//), I tried combining the $asArray(), $asObject() with my "users" variable but that did not work. When I used "users.$add(username);" instead of calling the $save method, my Firebase Forge just added the username without the object's properties.
app.factory('User', function ($firebase, FIREBASE_URL, Auth, $rootScope) {
var ref = new Firebase(FIREBASE_URL + 'users');
var users = $firebase(ref);
//var users = $firebase(ref).$asObject();
//var users = $firebase(ref).$asArray();
var User = {
create: function (authUser, username) {
users[username] = {
md5_hash: authUser.md5_hash,
username: username,
$priority: authUser.uid
};
//users.$add(username);
users.$save(username).then(function () {
setCurrentUser(username);
});
}, // end of create fxn
同样,我不能将用户[用户名]对象到我的火力地堡锻造用$保存或$添加AngularFire方法。我将不胜AP preciate任何帮助。
Again, I cannot insert the "users[username]" object into my Firebase Forge with the $save or $add AngularFire methods. I would greatly appreciate any help.
乔恩
推荐答案
现在你正在修改的绑定,然后调用 $保存
。你必须使用 $ asObject
或 $ asArray
来获取到 $保存
方法。
Right now you're modifying the binding and then calling $save
. You have to use $asObject
or $asArray
to get to the $save
method.
在您的情况下,虽然,你并不需要同步的任何对象,只救一个。您可以为用户创建一个新的对象,并使用 $更新
上的约束力。
In your case though, you don't need to sync any objects—just save one. You can create a new object for the user and use $update
on the binding.
app.factory('User', function ($firebase, FIREBASE_URL, Auth, $rootScope) {
var ref = new Firebase(FIREBASE_URL + 'users');
var users = $firebase(ref);
var User = {
create: function (authUser, username) {
users.$update(username, {
md5_hash: authUser.md5_hash,
username: username,
priority: authUser.uid
});
}, // end of create fxn
这篇关于如何插入对象插入到火力地堡锻造? - AngularFire 0.8.0 - Thinkster - 第7章的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!