Polymer + Firebase (Polymerfire): Cannot read property 'push' of undefined': 'this.$.query.ref.push(…)'

后端 未结 1 1811
天涯浪人
天涯浪人 2020-12-20 00:24

I\'m following a Polymer + Firebase tutorial video using the Polymer App Tool Kit (initiated with the polymer CLI).

When I try to push data to a Firebase collection,

相关标签:
1条回答
  • 2020-12-20 01:15

    First, I recommend comparing your code to the Polycast #58 source in GitHub, which might reveal the problem more clearly to you.

    this.$.query.ref (<firebase-query>.ref) refers to the ref property of Polymer.FirebaseDatabaseBehavior, which is computed with:

    __computeRef: function(db, path) {
      if (db == null ||
          path == null ||
          !this.__pathReady(path) ||
          this.disabled) {
        return null;
      }
    
      return db.ref(path);
    },
    

    Note that db.ref(path) never returns null, so ref being null must be a result of the if statement. Evaluating each condition might uncover the issue:

    • db == null

      • This property is computed from app.database() (never returns null), or is set to null when app is not defined (by <firebase-app>). Have you declared <firebase-app> with the proper app-name before importing the element that uses <firebase-query>?
    • path == null

      • You might not have set <firebase-query>.path. This is clearly not the case.
    • !this.__pathReady(path)

      • One of the path components might be an empty string or uninitialized. For your path (/users/[[user.uid]]/models), it's possible that user is not yet defined (user is not yet logged in), which results in an empty string in that path component (/users//models).
    • this.disabled

      • You might have set <firebase-query>.disabled. This is clearly not the case.
    0 讨论(0)
提交回复
热议问题