All HTML attributes are reactive by default. When an attribute’s value changes in the component HTML, the component is rerendered.
When you take control of an attribute by exposing it as a public property, the attribute no longer appears in the HTML output by default. To pass the value through to the rendered HTML as an attribute (to reflect the property), define a getter and setter for the property and call the
You can also perform operations in the setter. Use a field to hold the computed value.
This example exposes
title as a public property. It converts the title to uppercase and uses the property
_privateTitle to hold the computed value of the title. The setter calls
setAttribute() to reflect the property’s value to the HTML attribute.
setAttribute(). The generated HTML doesn’t include the
Before you set a value, check if the value has already been set by the consumer.
this.setAttribute() results in this markup.
To set these attributes, use
To hide HTML attributes from the rendered HTML, call