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

Bound data-* attributes being stripped from template children #1737

Closed
doliver-pulsemining opened this issue Jun 3, 2015 · 2 comments
Closed

Comments

@doliver-pulsemining
Copy link

In Polymer 1.0 Bound data-* attributes are not getting set on elements.
It applies to both custom and standard HTML elements.

This short example:

<dom-module id="div-test">
  <template>
    <div id="test_element" data-id="{{test}}" name="{{test}}">Some content</div>
  </template>
</dom-module>
<script>
  Polymer({
    is: 'div-test',
    ready: function() {
      this.test = "div_val_id";
    }
  })

Produces the following (note the lack of the data-id attribute):

<div id="test_element" name="div_val_id">Some content</div>

The only way to get the data-* element on the div is with javascript:

ready: function () {
  this.test = "div_val_id";
  this.$.test_element.dataset["id"] = this.test;
}

This worked correctly in Polymer 0.5.

@kevinpschaaf
Copy link
Member

In Polymer 1.0, the name="{{...}}" syntax indicates a property binding.

Also note that when binding to properties, dash-case names are converted to camelCase See Property name to attribute name mapping for details.

As such, your binding data-id="{{test}}" sets the dataId property on the element (which isn't anything a div).

In order to bind to dataset properties via data-* attributes, you need to use explicit attribute binding, which uses $= syntax: data-id$="{{test}}". That'll work for you.

This is covered in a bit more detail under Binding to native element attributes.

@doliver-pulsemining
Copy link
Author

Thank you very much for clarifying.

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

2 participants