使用Polymerfire时如何获取Firebase引用?
我对Polymer是新手,我一直在设置数据库数据。我设法使电子邮件身份验证工作,我需要保存用户创建后的用户数据。我使用firebase app元素初始化应用程序 以下是重要部分:使用Polymerfire时如何获取Firebase引用?,firebase,firebase-realtime-database,polymer-1.0,polymerfire,Firebase,Firebase Realtime Database,Polymer 1.0,Polymerfire,我对Polymer是新手,我一直在设置数据库数据。我设法使电子邮件身份验证工作,我需要保存用户创建后的用户数据。我使用firebase app元素初始化应用程序 以下是重要部分: this.$.auth.createUserWithEmailAndPassword(email, pass).then(function (user) { user.sendEmailVerification(); document.ge
this.$.auth.createUserWithEmailAndPassword(email, pass).then(function (user) {
user.sendEmailVerification();
document.getElementById("emaildialog").toggle();
var view = document.getElementById("r_view");
firebase.database().ref('/user/' + user['uid']).set({
name: view.name,
surname: view.surName
}).catch(function (err) {
console.log(err.message);
});
})
用户已成功创建,但用户数据将不会保存和删除
firebase.database不是函数“
抛出错误。我猜这是因为我无法访问范围中的firebase.database
函数。我找到了如何使用纯JavaScript解决问题的方法,但我不确定官方的“聚合方式”是什么
编辑:
我仍然无法让它工作。我设法获得了app object的引用,但似乎没有可用的数据库方法。我编写了一个简单的调试函数:
debugFunction: function () {
if (!!this.user) {
var fb = this.$.auth.app;
console.log(!!fb); // Output is true,
var database = fb.database();
}
}
我再次得到“uncaughttypeerror:fb.database不是函数(…)”
提前感谢,Jan您可以在firebase auth元素中获取firebase应用程序的引用。请确保在回调函数之外执行此操作,这样您就不必处理获取此
的正确范围的问题。如果必须,您可以执行。绑定或箭头函数
var app = this.$.auth.app;
然后,您可以使用app.database()
替换firebase