user3310115
user3310115

Reputation: 1460

Polymer issue for working file

Question 1: The below code works in polymer. I don't quite understand how. I didn't have to do something like var el = new Element() or I didn't have append it to the document explicitly.

Question 2: How can I eliminate the <my-element></my-element> tag?

MyElement.html

// After Importing all the necesarry files
var Element= Polymer({
    is: 'my-element'
    created: function (){
    this.textContent = "My Element"
    },
});

index.html (After importing all necessary files)

<body>
  <my-element></my-element>
</body>

Upvotes: 0

Views: 39

Answers (2)

Mr.Pandya
Mr.Pandya

Reputation: 2038

  1. If you use Polymer({}) constructor, it set up custom element's prototype chain and register it immediately. If you want setup and register whenever want use Polymer.class({}) , them call document.registerElement('my-element', MyElement);
  2. We cannot eliminate component tag, if we delete that tag LocalDom wont display

Upvotes: 0

Frank R.
Frank R.

Reputation: 1842

You can if you want,

// create an instance with createElement:
var el1 = document.createElement('my-element');

// ... or with the constructor:
var el2 = new MyElement();

Ref. https://www.polymer-project.org/2.0/docs/devguide/registering-elements#register-element

But, the beauty is the tag itself. More to read on custom elements,

https://www.polymer-project.org/2.0/docs/devguide/custom-elements https://www.webcomponents.org/introduction#specifications

Upvotes: 0

Related Questions