From Knockout tutorial:
Why this works?
<p>First name: <input data-bind="value: firstName" /></p>
While this doesn't?
<p>First name: <input data-bind="text: firstName" /></p>
ViewModel
// This is a simple *viewmodel* - JavaScript that defines the data and behavior of your UI
function AppViewModel() {
this.firstName = "Bert";
this.lastName = "Bertington";
}
Because in html, the typed text in an 'input type="text"' is stored in an attribute named value.
The value binding affect the value attribute of the element and the text binding alters the inner text of an element.
By writing
<input data-bind="text: firstName" />
you are trying to change the content of the input element. And an input doesn't allow a content.
<input value="where the value binding writes its data">
where the text binding writes its data
</input>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With