What are difference between hostAttributes and properties in polymer?

≡放荡痞女 提交于 2019-12-05 03:28:32

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:

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!