Fabian
Fabian

Reputation: 63

Using custom data-* attributes inside HTML5 <template> tag

I'm building a menu with a dom-repeat template like this:

        <template is="dom-repeat" items="{{appletsMenu}}">
              <a data-route="{{item.dataRoute}}" href="{{item.href}}">
                <iron-icon icon="{{item.icon}}" src="{{item.iconSrc}}" ></iron-icon>
                <span>{{item.name}}</span>
              </a>
        </template>

The data-route attribute is not filled though in the generated DOM:

<a href="...">...</a>
<a href="...">...</a>

It seems that the template only renders "normal" attributes like href. Am I'm missing something? Thanks.

Upvotes: 1

Views: 732

Answers (1)

vasek
vasek

Reputation: 341

To bind to an attribute, use $= rather than =. This results in a call to:

element.setAttribute(attr, value);

As opposed to:

element.property = value;

(source)

So in your case:

<a data-route$="{{item.dataRoute}}" href="{{item.href}}">

Upvotes: 2

Related Questions