GoogleWebComponents / firebase-element

Web components for the Firebase Web API
https://elements.polymer-project.org/elements/firebase-element
95 stars 79 forks source link

Upon 'add' i get Uncaught TypeError: Cannot read property 'ref' of undefined #32

Open devAtPolydeals opened 9 years ago

devAtPolydeals commented 9 years ago

I am able to successfully log in and get the token back but then when i try to add data i get exception, can you guys help? Below is my code:

<firebase-auth id="fbLogin" provider="anonymous" location="https://xxx.firebaseio.com" user="{{fbUser}}" statusKnown="{{statusKnown}}"></firebase-auth>

<firebase-collection id="fbLanding" location="https://xxx.firebaseio.com/" dataReady="{{userReady}}"></firebase-collection>

<div class="form-section">

 <gold-email-input required error-message="Please enter a valid email" label="Email contact" value="{{email}}" name="email" id="email" ></gold-email-input>
  <paper-button  type="submit" name="submit" raised on-click="buttonClick">Notify Me!</paper-button> </div>
<script>
    Polymer({
        is: 'landing-page',
        ready: function() {
            window.addEventListener('offline', function() {
            Firebase.goOffline();
          });
          window.addEventListener('online', function() {
            Firebase.goOnline();
          });
        },
        buttonClick: function() {
            this.$.fbLogin.login();
            this.$.fbLanding.add({
                timeStamp:Firebase.ServerValue.TIMESTAMP,
                email:this.$.email.value
            }); 
        },
        listeners: {
        'firebase-child-added': 'fireBaseResponse' 
        },
         fireBaseResponse: function(event) {
            var sessionId  = event.key();
            if (!sessionId){
                this.$.toast1.text="Ah Oh! something went wrong";
                this.$.toast1.toggleClass('errorClass', true);
            }
            else{
                this.$.toast1.toggleClass('errorClass', false);
                this.$.toast1.text="Thanks!";
            }
            this.$.toast1.show();
        }

    });  
</script>

The exception is at https://github.com/GoogleWebComponents/firebase-element/blob/master/firebase-collection.html#L227

marcus7777 commented 9 years ago

play with using both document and collection ; http://jsbin.com/lokegu/edit?html,output

devAtPolydeals commented 9 years ago

@marcus7777 thanks for your reply. You are using firebase push operation, i wanted to use the add method as mentioned in firebase-collection document to add data. see https://elements.polymer-project.org/elements/firebase-element?active=firebase-collection