Skip to main content

Attr Attribute

The $attr directive is used to dynamically bind HTML attributes to data properties.

Usage

~index.html
<img $attr="src:imageUrl,alt:imageAlt" />

How it Works

  • The framework parses the $attr attribute, splitting it into attribute-value pairs.

  • It sets up watchers for the referenced data properties.

  • When a property changes, the corresponding attribute is updated.

  • The element's attributes are dynamically modified.

Error Handling

If a referenced property doesn't exist, the attribute might not be set, and a warning could be logged to the console.

Note

note

This directive provides a flexible way to dynamically update various HTML attributes based on your application's state.