Search code examples
javascriptpolymerjsbin

Getting a Polymer element to appear in JSBin


I have the following code:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">

  <base href="http://polygit.org/polymer+:master/components/">

  <link href="polymer/polymer.html" rel="import">

  <link rel="import" href="paper-input/paper-input.html">
  <link rel="import" href="paper-dialog/paper-dialog.html">

  <title>JS Bin</title>
</head>
<body>

       <paper-input name="some"></paper-input>
          <paper-input name="some"></paper-input>

    <my-el></my-el>

    <dom-module id="my-el">
      <template>
        <style>
          display: block;
        </style>
         I AM HERE!

          <paper-input name="some"></paper-input>
          <paper-input name="some"></paper-input>

        <script>
          Polymer({
            is: "my-el",

            ready: function(){
              console.log("READY!?!");
            }
          })
        </script>
      </template>
    </dom-module>

    AND:

  </body>
</html>

Which is in this Jsbin: http://jsbin.com/qiyohaj/edit?html,console,output

Very simple questionL why on earth won't "x-el" display, nor run ready()...?


Solution

  • You have the script part of the webcomponent creation inside the template tag, the element never gets registered.

    Try replacing with this:

    <dom-module id="my-el">
      <template>
        <style>
          display: block;
        </style>
    
        <paper-input name="some"></paper-input>
        <paper-input name="some"></paper-input>
      </template>
      <script>
        Polymer({
          is: "my-el",
          ready: function(){
            console.log("ready");
          }
        });
      </script>
    </dom-module>