stuart-d2
11/8/2014 - 11:55 AM

Observables & data-bind "value" Text Fields. The two text fields are now observables that update automatically every time new data is put

Observables & data-bind "value" Text Fields. The two text fields are now observables that update automatically every time new data is put in.
• The first two fields are simple text data bound fields. • The second two fields have the input html attr and the data-bind "value" attribute • the strings for first and last name were just simple text strings. Now they are arguments enclosed within ko.observable() methods.

function AppViewModel() {
    this.firstName = ko.observable("Bert");
    this.lastName = ko.observable("Bertington");
}

// Activates knockout.js
ko.applyBindings(new AppViewModel());

<p>First name: <strong data-bind="text: firstName"></strong></p>
<p>Last name: <strong data-bind="text: lastName"></strong></p>

<p>First name: <input data-bind="value: firstName" /></p>
<p>Last name: <input data-bind="value: lastName" /></p>