Polymerfire 类型错误

Polymerfire TypeError

我是 Polymer 的新手,我正在尝试使用 Firebase-document 组件保存用户数据。

以下是相关的代码片段:

组件初始化:

    <firebase-document id="document" app-name="nameoftheapp"
                       path="[[userDataPath]]" data="{{userData}}">
    </firebase-document>

和 javascript 部分:

    Polymer({
        is: 'registration-view',

        properties: {
            userData: Object,
            userDataPath: {
                type: String,
                notify: true
            }
        },

        debugFunction: function () {
            user = this.domHost.user;
            this.userDataPath = '/users/' + user.uid;
            this.userData.firstName = "fname";
            this.userData.lastName = "lname";
            console.log(user);
            console.log(this.userDataPath);
            this.$.document.save(this.userDataPath).then(function () {
                console.log("success");
            });
        }, 
        ......

当我调用调试函数时,我得到了

Uncaught (in promise) TypeError: c[b] is not a function(…).

堆栈跟踪:

1) debugFunction @ registration-view.html:106
2) save @ firebase-document.html:82
3) (anonymous function) @ firebase-document.html:93
4) c @ firebase-app.js:formatted:939

错误是在最小化的 firebase-app.js 文件中抛出的,所以我对此不是很聪明。希望一切都配置正确。用户身份验证工作正常,应用程序名称也可以(如果不是应用程序未初始化将抛出错误)。

我试图模拟数据库中的数据,但 firebase 文档没有加载它们。我设置了数据库规则,使数据 public 以消除潜在的授权问题,但它没有帮助。

{
  "rules": {
//     ".read": "auth != null",
    ".read": true,
//     ".write": "auth != null"
    ".write": true
  }
}

尝试 2:

我找到了 如何保存数据,这里是代码:

<firebase-document id="document" app-name="doctor-appointment-system" log>
</firebase-document>

Javascript部分:

    debugFunction: function () {
        this.$.document.path = null;
        this.$.document.data = {
            'firstName': this.$.fninput.value,
            'lastName': this.$.lninput.value
        };
        console.log('users/' +  this.domHost.user.uid);
        this.$.document.save('users',  this.domHost.user.uid);
    },

使用此设置,我遇到了另一个错误。这是控制台的输出:

users/Z5uAEYO2S1g2JYClpkk1Vtw130i2

app-storage-behavior.html:350 Setting Firebase value at users/Z5uAEYO2S1g2JYClpkk1Vtw130i2 to Object {firstName: "", lastName: ""}

firebase-database-behavior.html:61 Uncaught (in promise) TypeError: Cannot read property 'ref' of undefined(…)_setFirebaseValue

它在 firebase-database-behaviour.html 中的以下行失败:

var result = this.db.ref(path).set(leaf ? value.$val : value);

看起来配置有问题,但身份验证工作正常,所以我一无所知。

我被困在这个问题上,所以我们将不胜感激。

谢谢,简

我找到了解决方案,但我仍然不确定问题的本质是什么。我的应用程序的结构是单页应用程序的结构。我有一个 core-scaffold 元素,它由工具栏、app-route、iron-pages 和 firebase-auth 元素组成。上面的代码位于 registration-view 中,当足够的 URL 匹配时,它由 iron-pages 延迟加载。我尝试将代码直接移动到 core-scaffold 文件,一切正常。 令人惊讶的是,当我在注册视图中调用代码时,它也有效。事实证明,如果我在 core-scaffold.html 中导入 firebase-document.html,则不会在 children.[=10 中抛出错误=]

如果有人解释是什么原因,我将不胜感激。

谢谢,简