Two-way binding keeps a component property and something connected to it in sync in both directions. A property can supply a value to an input or child component; a change made through that input or child can then update the property. section 8.7 section 9.8
Sliders that recalculate an area
An area calculator binds range inputs to width and height. Moving either slider updates its component property; the displayed value changes, and a computed area is recalculated. In wrec, the slider template uses `value:input="this.${property}"` for the binding. section 8.7
Listing 8.6 makeSlider function
function makeSlider(label: string, property: string) {
return html`
<div>
<label for="${property}">${label}</label>
<input
id="${property}"
type="range"
min="1"
max="10"
value:input="this.${property}"
/>
<span>this.${property}</span>
</div>
`;
}
The slider helper shows the input binding beside the label and displayed property value. section 8.7
The two directions matter. Lit’s `@property()` makes an attribute set the corresponding property and updates rendered output, but changing the property does not automatically change the attribute. Use `@property({ reflect: true })` when the attribute must also follow property changes. That attribute–property relationship is distinct from binding a user-editable input to a property. section 5.2 section 8.7
Binding can also connect components. A wrec parent passes its color property to both a greeting component and a radio group. Changing the selected radio value updates the shared color, so the greeting changes too. This automatic synchronization reduces the event-handling code needed by the radio-group implementation. FAST’s template system also includes two-way data binding, though no binding syntax is specified here. section 9.8 section 8.10 section 7.1


