diff options
Diffstat (limited to 'alpinejs/packages/docs/src/en/directives/modelable.md')
-rw-r--r-- | alpinejs/packages/docs/src/en/directives/modelable.md | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/alpinejs/packages/docs/src/en/directives/modelable.md b/alpinejs/packages/docs/src/en/directives/modelable.md new file mode 100644 index 0000000..83eb789 --- /dev/null +++ b/alpinejs/packages/docs/src/en/directives/modelable.md @@ -0,0 +1,37 @@ +--- +order: 7 +title: modelable +--- + +# x-modelable + +`x-modelable` allows you to expose any value by name as the target of the `x-model` directive. + +Typically this feature would be used in conjunction with a backend templating framework like Laravel Blade. It's useful for abstracting away Alpine components into backend templates and exposing state to the outside through `x-model` as if it were a native input. + +Here's a simple example of using `x-modelable` to expose a variable for binding with `x-model`. + +```alpine +<div x-data="{ number: 5 }"> + <div x-data="{ count: 0 }" x-modelable="count" x-model="number"> + <button @click="count++">Increment</button> + </div> + + Some Number: <span x-text="number"></span> +</div> +``` + +<!-- START_VERBATIM --> +<div class="demo"> + <div x-data="{ number: 5 }"> + <div x-data="{ count: 0 }" x-modelable="count" x-model="number"> + <button @click="count++">Increment</button> + </div> + + Number: <span x-text="number"></span> + </div> +</div> +<!-- END_VERBATIM --> + +As you can see the outer scope property "number" is now bound to the inner scope property "count". + |