What are difference between hostAttributes and properties in polymer?
Asked Answered
V

2

12

I'm doing migration from 0.5 to 1.0.

While reading, I notice 2 different way on declaring attributes, using hostAttributes and properties.

What are difference between those 2 ?

Volpe answered 9/6, 2015 at 5:7 Comment(0)
R
7

Host attributes are attributes that do not match to an element's corresponding Javascript property (which you declare in properties). This includes attributes like class, tabindex, data-* attributes, aria-roles, etc. To declare them during create-time, you must set them in the hostAttributes object. If you are going to bind values into them, you must use $= (which calls Element.setAttribute) rather than =.

Sources:

Roselleroselyn answered 9/6, 2015 at 7:12 Comment(1)
Not class. The class attribute can't be configured using hostAttributes.Domino
T
0

If a custom element needs HTML attributes set on it at create-time, the attributes may be declared in a hostAttributes property on the prototype, where keys are the attribute names and values are the values to be assigned.

But now since listeners and hostAttributes have been removed from element metadata

we can use _ensureAttribute as an alternative to define these kind of attributes

ex:-

this._ensureAttribute('tabindex', 0); you can declare all such properties in ready

Tushy answered 10/8, 2018 at 10:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.