0

I need to append this polymer element to index.html which i did with no problem but the problem is i cannot append anything to that "items" div how can i do this? i think that the element is not yet appended to the index.html page so the script could not catch the "items" div.

 <link rel="import" href="../bower_components/polymer/polymer.html">
    <script src='https://cdn.firebase.com/js/client/2.2.1/firebase.js'></script>
    <link rel="import" href="../bower_components/paper-icon-button">
    <script src='https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js'></script>


    <dom-module id="sample-page">
      <style>


      </style>
      <template>
        <div class="items">



        </div>

      </template>
    </dom-module>
    <script>
      Polymer({
        is: "sample-page",

      });

        $(document).ready(function(){

      ;
      var rootRef = "myfirebase ref......."
      rootRef.on("child_added", function (snapshot, prevChildKey) {

        var pointData = snapshot.val();
        snapshot.forEach(function (childSnap) {

         $('#items').append( pointData.user);
          var key = childSnap.key();
    //console.log('here come');
    //      console.log("Title: " + pointData.user);

        })

    //  });


      //  });
    </script>
Nazil
  • 21
  • 1
  • 7

1 Answers1

0

You need to wait until the polymer elements / web components are loaded.

Instead of $(document).ready(function(){});

Use the code below (or JQuery equivalent)

window.addEventListener('WebComponentsReady', function(e) {
    ...
});
Chris W
  • 785
  • 8
  • 18