Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

behavior difference between <my-component/> and <my-component></my-component> #899

Closed
ogodineau opened this issue Nov 9, 2014 · 3 comments

Comments

@ogodineau
Copy link

Hi,
i've tried some tutorials and i've found something weird i don't understand :
On my index.html i've declared into the body

 <my-component/><my-component/>

thus, i've hoped my component appears twice. In fact,it appears only once in chrome.

But If i had written into the body

<my-component></my-component><my-component></my-component>

my component would appear twice in chrome!

Here my polymer elements

 <link rel="import" href="../bower_components/polymer/polymer.html">
<polymer-element name="app-globals" >
  <script>
  (function() {
    var values = {};

    Polymer({
       ready: function() {
         this.values = values;
         for (var i = 0; i < this.attributes.length; ++i) {
           var attr = this.attributes[i];
           values[attr.nodeName] = attr.nodeValue;
             }
           }
        });
      })();
  </script>
</polymer-element>

<polymer-element name="my-component">
<template>
<app-globals id="globals"  firstname="Addy" lastname="Osmani"></app-globals>
<div id="firstname">{{$.globals.values.firstname}}</div>
<div id="lastname">{{$.globals.values.lastname}}</div>
 </template>
  <script>
      Polymer({
          ready: function() { 
            console.log('Last name: ' + this.$.globals.values.lastname); 
          }
      });
  </script>
</polymer-element>
@ogodineau
Copy link
Author

I wish it was because it's html but not xhtml
However, If the use of empty element is incorrect why my component appears on the page?

@ebidel
Copy link
Contributor

ebidel commented Nov 9, 2014

Only certain HTML Elements can be self-closing according to the HTML parser. Therefore, custom elements always need to be of the form:

<my-component></my-component>

<my-component/> will not work. More info: #628

@astericky
Copy link

Thanks Eric! I was wondering about this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants