Bindings
Sometimes we need to get the value of a property or attribute from a DOM element and save it in a variable.
To do this, we can simply declaratively bind a compVar
to an attribute or property of the element using the <
symbol:
Note the $divEl<this
, we are ordering Bemtv to set the DOM element as the value of the divEl
property.
If we wanted an element instance as in useElManager()
we could do:
Numeric inputs
To get the current value of inputs
we can use the value
property and if we want this value to be converted to number
automatically we must define the initial value of the property that will keep the value as a number:
Select element
Binding with the select
element is similar to inputs
, however, if you use themultiple
attribute you must define an array for the property that will bind with the select
value:
Checkbox inputs
Similar to select
, checkbox inputs
can define an array for the property that will be bound to the list of checked
items:
Last updated