Svelte 101: Bindings

To sync an attribute of an element to a variable, you’ll need to 1) Add an event handler to the element - so changes on the element will update the variable. 2) Pass the variable to the attribute - so changes on the variable will update the element Instead of doing 2 steps, we can combine both into 1 bind: directive. In this video, we are going to look at how we can use binding to bind a variable to an attribute of an element. p/s: binding works for component too! Introduction 00:00 Syncing an attribute value to a variable 00:12 Binding element attribute with the bind: directive 01:52 Shorthand for bind: 04:57 Binding component props 05:48 --- 💻 REPL 📚 Related Resources Svelte Svelte REPL Svelte Tutorial: Bindings Svelte Tutorial: Component Bindings 🥰 Support me
Back to Top