Skip to content

Form Bindings

MrCai edited this page Jul 21, 2022 · 1 revision

c-model directive imposes a two-way binding between element and data. Think of it as a combination of c-bind and c-on.

When we are saying "two-way binding", we mean that: The event triggered on element will result in a change on data, and the change on data will be reflected on element.

This directive only works for form elements, including:

  • <input type="text">
  • <input type="checkbox"> (Single or multiple)
  • <input type="radio">
  • <textarea>
  • <select>
<!-- index.html -->
<input type="text" c-model="message" />
// main.ts
data: {
  message: "",
}
<!-- Compile result -->
<input type="text" />

For more examples, see this demo.

Clone this wiki locally