Attribute Bindings

Permalink to "Attribute Bindings"

Now, update the view when the rating attribute changes; this is similar to an input updating its view when you set <input value="newValue">. Luckily, the web component lifecycle includes the attributeChangedCallback. Update the rating by adding the following lines:

rating-element.

Permalink to "rating-element."

In order for the attributeChangedCallback to trigger, you must set a static getter for RatingElement.observedAttributes which declares which attributes should be observed for changes. You then set the rating attribute declaratively in the DOM. Give it a try:

index.html

Permalink to "index.html"

The rating should now be updating declaratively!