Strictly Programming

Polymer: Register an element

Posted in Polymer by sqllyw on 08/23/2016

Register an element in Polymer

It’s quite easy to register an element in Polymer, just remember the element name should be separated by a dash, example: this works:”my-element”, this will not work:”myelement”

  
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>register an element</title>
    <!-- import latest release version of all components from polygit -->
    <base href="https://polygit.org/components/">
    <script src="webcomponentsjs/webcomponents-lite.js"></script>
    <link href="polymer/polymer.html" rel="import">
</head>

<body>
    <my-elem></my-elem>
</body>

<dom-module id="my-elem">
    <script>
        Polymer({
            is: "my-elem",
            ready: function () {
                this.textContent = 'I am my-elem'
            }
        })
    </script>
</dom-module>

</html>

try it in jsFiddle

Advertisements
Tagged with:

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: