Agenda
- What is data binding?
- Types of data binding.
- Render data conditionally.
If you have started your journey as a developer already then you must have heard these terms data binding and rendering.
There are many high level data binding definitions are available online but I will try to keep it as simple as I can.
What is Data Binding?
In simple words when you map your data from Backend to Frontend called data binding.
In LWC our backend will be JavaScript/Apex and frontend will be HTML.
Types of Data Binding?
- Using Expressions
- Using getter properties
Example of data binding using Expressions
You can also make the expression value dynamic, like on any button click or text change. It's up to your requirements.
In below example I am changing the expression value on change of my input text in HTML.
Example of Data Binding using getter properties
Render Data Conditionally
To render data conditionally you can use "template if:true={expression}" and "template if:false={expression}"
In your expression you can have static or dynamic expressions. Also you can use your getter properties instead of expression as per your requirement.
In below example I am using conditional rendering based on the click of the checkbox in LWC.
0 Comments