So today we will look into two way data binding. So we have already looked into V model in the past. So in this lecture, we'll just go over it one more time. And then we'll also look into what's the difference between V bind and V model? And when do you When do you need to use what so I guess most of you by now would be wondering, what is the difference between these two properties like these two directives, V model and V bind? So let's start to get some clarity on it so that you can know when to use what Alright.
So in the previous lecture, we talked about data binding, right? So we talked about how v bind is used to bind variables. So you could think v model is used to bind the value of a data property to an input field. So if you have an input field, and I want the value of it, and if I want to, and I want its value to be directly corresponding to a variable or to a data property, why don't I use v bind and value Let's say name right? Why did I not do this? And why did I do?
Right? So these are two different directives almost having the same purpose getting the data property name to be bound with the input field. But why did I use v model till now and why did I not use v bind? The point is V bind is one way data binding or just data binding, whereas, V model is two way data binding. So, now we have two different fields one is using v bind and when he's using the model, so, in terms of V by n, what happens is the data property is bound to the value of the input field. So, whenever I change the data property, the value will change.
But, whenever I change the value that determines property will not change. For example, if I try to add another variable are the techniques of string, you can see that even though these two are linked to the same data property, this name that is used in the V model doesn't get updated. The reason is, it's only bound in one way. So the name is only bound to the input field. But the input fields value is not bound to the name. Whereas in V model, if either of the two properties change, both of them get updated.
So let's try to change the name in the V bind. Let's see if it changes in the V model. So if I add hyphen, developer or other extra characters, you can see that this value doesn't change. But if I remove this, right, if I do this, the upper value automatically changes. Right. So the reason is when you're using v model, the name is to be bound to this input field.
Meaning if Even if the value changes, it gets updated to the name. Or even if the name changes it gets it gets updated to the value. So v model directive is used when you want to be data binding, whereas a V bind directive is used when you want only one way data binding. So I hope that's clear. I guess this example would be sufficient. So that's it for this lecture.
So in the next one, we look into events and what are the different types of events available, and we'll just go through a interaction of the events. Then later, we can focus on keyboard events and mouse events, etc. It's gonna be a lot of fun. I hope you've seen the next one.